Skip to content

Instantly share code, notes, and snippets.

@highfestiva
Created September 13, 2021 08:05
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 highfestiva/e1cbebbb31d4d116a33cccc9905de3cd to your computer and use it in GitHub Desktop.
Save highfestiva/e1cbebbb31d4d116a33cccc9905de3cd to your computer and use it in GitHub Desktop.
Epoch-ms conversion
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