5

The format I have been given yyyy-MM-dd'T'HH:mm:ss.SSS'Z'. However, this isn't working with my code which is

datetime.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 ?

tsaebeht
  • 1,570
  • 5
  • 18
  • 32

1 Answers1

7

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

tsaebeht
  • 1,570
  • 5
  • 18
  • 32
Devasta
  • 1,489
  • 2
  • 17
  • 28