Trying to write the date in a format I like. Currently, I found by mistake that this works:
datetime.now(timezone.utc).strftime("%Y%m%dT%TZ")
'20241207T11:57:37Z'
Note that Im not specifying %H:%M:%S
(but I could)
The %T
does that instead, but the option isn’t documented afaik.
But it was somewhat unexpected that %T
does the same.
Apparently the reason could be:
The full set of format codes supported varies across platforms, because Python calls the platform C library’s
strftime()
function, and platform variations are common.
- So my question is: do we have a crossplatform way to specify it in a single character? I don’t fully understand the details.
Currently, I do: date = datetime.now(timezone.utc).strftime("%Y_%m_%d_T%H_%M_%SZ")
but I don’t like it very much.