Skip to content

Instantly share code, notes, and snippets.

@nooperpudd
Created March 27, 2019 02:22
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 nooperpudd/3c6fd7d239a00586e9ea7a209afe39e0 to your computer and use it in GitHub Desktop.
Save nooperpudd/3c6fd7d239a00586e9ea7a209afe39e0 to your computer and use it in GitHub Desktop.
np_datetime64_to_timestamp
def np_datetime64_to_timestamp(dt64, decimals=6):
"""
https://stackoverflow.com/questions/13703720/converting-between-datetime-timestamp-and-datetime64
convert np.datetime64 to python datetime.timestamp
:return: timestamp
"""
value = (dt64 - np.datetime64("1970-01-01T00:00:00")) / np.timedelta64(1, 's')
return float(np.around(value, decimals=decimals))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment