Skip to content

Instantly share code, notes, and snippets.

@ktchernov
Last active June 7, 2022 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktchernov/bf3d3f10b168a836f8e60867d3be1f64 to your computer and use it in GitHub Desktop.
Save ktchernov/bf3d3f10b168a836f8e60867d3be1f64 to your computer and use it in GitHub Desktop.
Python dates
import datetime
# Python date and datetime in ISO 8601 format
# Example local timezone is UTC+12
isodate = datetime.datetime.now().date().isoformat()
print(isodate) # prints 2022-06-07 - Current timezone
isodateutc = datetime.datetime.utcnow().date().isoformat()
print(isodateutc) # prints 2022-06-06 - UTC timezone
isodatetime = datetime.datetime.now().isoformat()
print(isodatetime) # prints 2022-06-07T09:25:42.377201 - Current timezone
isodatetimez = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
print(isodatetimez) # prints 2022-06-06T21:25:42Z - UTC timezone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment