Last active
February 18, 2019 19:08
-
-
Save rreece/4fd5ec6c884bc1a82563c6d4b8367f3c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
""" | |
Should follow: | |
https://en.wikipedia.org/wiki/ISO_8601 | |
See also: | |
- https://stackoverflow.com/questions/2150739/iso-time-iso-8601-in-python | |
""" | |
import time | |
timestamp = time.strftime('%Y-%m-%d-%Hh%M') # '2019-02-14-16h20' | |
timestamp = time.strftime('%Y-%m-%dT%H:%M:%S') # '2019-02-15T13:18:09' | |
import datetime | |
utc_offset_sec = time.altzone if time.localtime().tm_isdst else time.timezone | |
utc_offset = datetime.timedelta(seconds=-utc_offset_sec) | |
datetime.datetime.now().replace(microsecond=0).replace(tzinfo=datetime.timezone(offset=utc_offset)).isoformat() # '2019-02-15T12:28:43-08:00' | |
import pytz | |
datetime.datetime.now().replace(microsecond=0).astimezone(pytz.timezone("America/Los_Angeles")).isoformat() # '2019-02-15T12:32:44-08:00' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also in bash: