Last active
March 1, 2024 20:24
-
-
Save blaylockbk/1677b446bc741ee2db3e943ab7e4cabd to your computer and use it in GitHub Desktop.
Convert numpy.datetime64 to datetime.datetime
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
from datetime import datetime | |
import numpy as np | |
def to_datetime(date): | |
""" | |
Converts a numpy datetime64 object to a python datetime object | |
Input: | |
date - a np.datetime64 object | |
Output: | |
DATE - a python datetime object | |
""" | |
timestamp = ((date - np.datetime64('1970-01-01T00:00:00')) | |
/ np.timedelta64(1, 's')) | |
return datetime.utcfromtimestamp(timestamp) |
Cool! Thanks
Thanks
well done, thanks!
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A simple elegant solution which is surprisingly not fount on the net.