Skip to content

Instantly share code, notes, and snippets.

@matutter
Created August 31, 2019 01:06
Show Gist options
  • Select an option

  • Save matutter/a5890215c4b6c6ae141538da7ecccb42 to your computer and use it in GitHub Desktop.

Select an option

Save matutter/a5890215c4b6c6ae141538da7ecccb42 to your computer and use it in GitHub Desktop.
Shows how ms-since-epoch TS that are truncated to fit in int32_t space will look.
from subprocess import check_output
from datetime import datetime
ms_since_epoch = check_output([
"node",
"-e",
"console.log(require('moment')().valueOf())"
])
dt = datetime.fromtimestamp(float(ms_since_epoch) / 1000.0)
print(ms_since_epoch)
print(dt)
ts = ms_since_epoch[:10]
dt = datetime.fromtimestamp(int(ts))
print(ts)
print(dt)
ts = ms_since_epoch[-11:]
dt = datetime.fromtimestamp(int(ts))
print(ts)
print(dt)
@matutter
Copy link
Author

# python main.py
1567213448944

2019-08-30 21:04:08.944000
1567213448
2019-08-30 21:04:08
7213448944

2198-08-01 18:49:04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment