Last active
June 7, 2022 21:43
-
-
Save ktchernov/bf3d3f10b168a836f8e60867d3be1f64 to your computer and use it in GitHub Desktop.
Python dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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