To get a date string with milliseconds, use [:-3]
to trim the last three digits of %f
(microseconds):
>>> from datetime import datetime
>>> datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
'2020-05-04 10:18:32.926'
Related Contents:
- How do I turn a python datetime into a string, with readable format date?
- How can I convert 24 hour time to 12 hour time?
- How do I get the current time?
- How do I get the day of week given a date?
- How do I get the current time in milliseconds in Python?
- How do I convert seconds to hours, minutes and seconds?
- How can I convert a datetime object to milliseconds since epoch (unix time) in Python?
- How do I get a value of datetime.today() in Python that is “timezone aware”?
- Django auto_now and auto_now_add
- How to print pandas DataFrame without index
- Convert python datetime to epoch with strftime
- Convert datetime to Unix timestamp and convert it back in python
- Python UTC datetime object’s ISO format doesn’t include Z (Zulu or Zero offset)
- What does %s mean in a Python format string?
- How are booleans formatted in Strings in Python?
- When to use %r instead of %s in Python? [duplicate]
- Calculate Time Difference Between Two Pandas Columns in Hours and Minutes
- Convert hex to binary
- Find oldest/youngest datetime object in a list
- How to round the minute of a datetime object
- Convert dataframe index to datetime
- How can I extract hours and minutes from a datetime.datetime object?
- str.format() raises KeyError
- Pandas: Convert Timestamp to datetime.date
- Pythonic difference between two dates in years?
- User-friendly time format in Python?
- RFC 1123 Date Representation in Python?
- Getting the date of 7 days ago from current date in python [closed]
- Find the closest date to a given date
- Parameter unsupported when inserting int
- How to truncate a string using str.format in Python?
- How would I compute exactly 30 days into the past with Python (down to the minute)?
- What is the difference between !r and %r in Python?
- Comparison between datetime and datetime64[ns] in pandas
- Subtract hours and minutes from time
- f-string syntax for unpacking a list with brace suppression
- “import datetime” v.s. “from datetime import datetime”
- Django – Get only date from datetime.strptime
- What is the difference between python functions `datetime.now()` and `datetime.today()`?
- advanced string formatting vs template strings
- How do you determine a processing time in Python?
- Weird timezone issue with pytz
- Converting datetime to POSIX time
- Query Mongodb on month, day, year… of a datetime
- How to calculate next Friday?
- Python string formatting: reference one argument multiple times
- pytz utc conversion
- Does Python do variable interpolation similar to “string #{var}” in Ruby? [duplicate]
- AttributeError: ‘str’ object has no attribute ‘strftime’
- How do I use string formatting to show BOTH leading zeros and precision of 3?