Skip to content

Instantly share code, notes, and snippets.

@oliora
Created November 8, 2022 14:58
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 oliora/0927422b79cd779768b58b05ee1a9119 to your computer and use it in GitHub Desktop.
Save oliora/0927422b79cd779768b58b05ee1a9119 to your computer and use it in GitHub Desktop.
Shell timestamp conversion aliases
alias to-timesptamp-ms="python3 -c 'import datetime, sys; s = sys.argv[1]; s = s[:-1] if s[-1] == \"Z\" else s; print(round(datetime.datetime.fromisoformat(s).replace(tzinfo=datetime.timezone.utc).timestamp() * 1000))'"
alias from-timesptamp-ms="python3 -c 'import datetime, sys; t = int(sys.argv[1]); print(datetime.datetime.utcfromtimestamp(t/1000).strftime(\"%Y-%m-%dT%H:%M:%S.%f\")[:-3]+\"Z\")'"from-timesptamp-ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment