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'
More 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?
- String formatting: % vs. .format vs. f-string literal
- How to print a date in a regular format?
- Convert UTC datetime string to local datetime
- How to make a timezone aware datetime object in Python?
- Pandas Dataframe line plot display date on xaxis
- Parsing datetime strings containing nanoseconds
- Number of days between 2 dates, excluding weekends
- Get current time in milliseconds in Python?
- Generating random dates within a given range in pandas
- Inserting a Python datetime.datetime object into MySQL
- Converting string “Jun 1 2005 1:33PM” into datetime
- pandas to_datetime parsing wrong year
- partial string formatting
- Python TypeError: non-empty format string passed to object.__format__
- Python/Pandas convert string to time only
- Convert dataframe index to datetime
- How to add/subtract time (hours, minutes, etc.) from a Pandas DataFrame.Index whos objects are of type datetime.time?
- Plural String Formatting
- How to get current date and time from GPS unsegment time in python
- How to convert a Date string to a DateTime object?
- Seaborn tsplot does not show datetimes on x axis well
- Group DataFrame in 5-minute intervals
- How to convert Python’s .isoformat() string back into datetime object [duplicate]
- Python summing up time
- Ceil a datetime to next quarter of an hour
- Clean way to convert quarterly periods to datetime in pandas
- Python: Matplotlib avoid plotting gaps
- Python Pandas : pandas.to_datetime() is switching day & month when day is less than 13