Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python UTC timestamp with ISO format

I know this has been asked but there was no solution provided there. Python UTC datetime object's ISO format doesn't include Z (Zulu or Zero offset)

I am looking for a clean way of generating UTC time stamp with this format in Python. The format I need is 2013-10-29T09:38:41.341Z.

Specifically, I need to include "Z" at the end. Python's datetime.utcnow().isoformat() does not append "Z" at the end.

Note that manually appending "Z" is not a solution I can accept. I am looking for a clean way to do this.

What is the clean way to generate UTC timestamp in ISO format with the suffix Z?

like image 816
leopoodle Avatar asked Dec 06 '22 15:12

leopoodle


1 Answers

How about something like

datetime.utcnow().isoformat()[:-3] + 'Z'
like image 80
Tomasz Swider Avatar answered Dec 20 '22 14:12

Tomasz Swider