Created
September 10, 2018 19:14
-
-
Save weech/a0c8397491008a13efd4e637d3ff7682 to your computer and use it in GitHub Desktop.
Convert a numpy datetime64 to a python datetime.datetime
This file contains 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
import datetime as dt | |
import numpy as np | |
def to_datetime(date: np.datetime64) -> dt.datetime: | |
""" Converts a numpy datetime64 object to a python datetime object """ | |
timestamp = ((date - np.datetime64('1970-01-01T00:00:00')) | |
/ np.timedelta64(1, 's')) | |
return dt.datetime.utcfromtimestamp(timestamp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment