Given the following datetime:
d = datetime.datetime(2018, 10, 9, 8, 19, 16, 999578, tzinfo=dateutil.tz.tzoffset(None, 7200))
d.isoformat() results in the string:
'2018-10-09T08:19:16.999578+02:00'
How can I get a string with milliseconds instead of microseconds:
'2018-10-09T08:19:16.999+02:00'
strftime() will not work here: %z returns 0200 istead of 02:00 and has only %f to get microseconds, there is no placeholder for milliseconds.
str.format()
, if you can get microseconds & millisecs from datetime object you can format the strings representations in any waystr.format
can do.strftime()
is exactly the provided method for that. – Edana