[Django]-DateTime in ISO 8601 + TimeZone and without microseconds

11👍

Set microsecond as 0:

t = timezone(settings.TIME_ZONE).localize(datetime.now()).replace(microsecond=0)
t.isoformat()

datetime.datetime.replace(...) will return a new datetime object with specified attribute modified.

Leave a comment