Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7673567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:32:28+00:00 2026-05-31T16:32:28+00:00

>>> a = str(datetime.now()) >>> a ‘2012-03-22 11:16:11.343000’ I need to get a string

  • 0
>>> a = str(datetime.now())
>>> a
'2012-03-22 11:16:11.343000'

I need to get a string like that: '16:11.34'.

Should be as compact as possible.

Or should I use time() instead?
How do I get it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:32:29+00:00Added an answer on May 31, 2026 at 4:32 pm

    What about:

    datetime.now().strftime('%M:%S.%f')[:-4]

    I’m not sure what you mean by “Milliseconds only 2 digits”, but this should keep it to 2 decimal places. There may be a more elegant way by manipulating the strftime format string to cut down on the precision as well — I’m not completely sure.

    EDIT

    If the %f modifier doesn’t work for you, you can try something like:

    now=datetime.now()
    string_i_want=('%02d:%02d.%d'%(now.minute,now.second,now.microsecond))[:-4]
    

    Again, I’m assuming you just want to truncate the precision.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Handler Implementation class TestHandler(RequestHandler, Jinja2Mixin): def get(self): channel_id = str(random.randint(1, 10000)) + str(datetime.now()) chat_token
str_replace('Ê','',$line); Ain't working. Is there some special string that represents that?
string str = one three; string::iterator it; string add = two ; Lets say
static void Main() { string str; str = Console.ReadLine(); while (str != null)//HERE! {
Java has a convenient split method: String str = The quick brown fox; String[]
I've made my Logger, that logs a string, a static class with a static
I have a script that has been written that I need to change the
I want to create a file with date. DateTime time_now = DateTime::UtcNow; String^ time_str
in my repository i have public function findAllMorosos($date = 'now') { $datetime = new
I've got a list of dates (datetimes): >>> print str(range) [datetime.datetime(2011, 12, 15, 0,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.