Skip to content

Instantly share code, notes, and snippets.

@philippreston
Created April 14, 2016 08:14
Show Gist options
  • Save philippreston/41a52fa93491359594ee45c63cb9af3c to your computer and use it in GitHub Desktop.
Save philippreston/41a52fa93491359594ee45c63cb9af3c to your computer and use it in GitHub Desktop.
Convert Timestamps to Human Readable
def get_time(epoch_us, fmt="%Y-%m-%d %H:%M:%S.%f"):
dt = float(epoch_us / 1000000.0)
v = datetime.datetime.fromtimestamp(dt)
return v.strftime(fmt)
def get_micros_for_time(stime, fmt="%Y-%m-%d %H:%M:%S.%f"):
assert stime
tt = time.strptime(stime, fmt)
assert tt
ts = time.mktime(tt)
return int(ts) * 1E6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment