How to print current GMT time in a specific format in python
19,085
https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior
Python uses the above linked directives to format time.
So, for example, if you try something like:
import datetime
datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f%Z")
This should display the format you mentioned in the right way
Author by
tsaebeht
Updated on June 09, 2022Comments
-
tsaebeht almost 2 years
The format I have been given
yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
. However, this isn't working with my code which isdatetime.utcnow().strftime("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
The output is simply:
yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
Why does this not work? What is the fix ?
-
gzerone over 3 yearsdatetime.utcnow() :)
-
saurabh gupta almost 3 years@gzerone you are an angel.