Created
April 14, 2016 08:14
-
-
Save philippreston/41a52fa93491359594ee45c63cb9af3c to your computer and use it in GitHub Desktop.
Convert Timestamps to Human Readable
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
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