Created
September 13, 2021 08:05
-
-
Save highfestiva/e1cbebbb31d4d116a33cccc9905de3cd to your computer and use it in GitHub Desktop.
Epoch-ms conversion
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 dateutil.parser | |
from datetime import datetime | |
import pytz | |
def local2timestamp(s): | |
return int(dateutil.parser.parse(s).timestamp() * 1000) | |
def timestamp2local(t): | |
return datetime.fromtimestamp(t/1000).isoformat().replace('T',' ') | |
def utc2timestamp(s): | |
return int(dateutil.parser.parse(s).replace(tzinfo=pytz.utc).timestamp() * 1000) | |
def timestamp2utc(t): | |
return datetime.utcfromtimestamp(t/1000).isoformat().replace('T',' ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment