Skip to content

Instantly share code, notes, and snippets.

@blaylockbk
Last active March 1, 2024 20:24
Show Gist options
  • Save blaylockbk/1677b446bc741ee2db3e943ab7e4cabd to your computer and use it in GitHub Desktop.
Save blaylockbk/1677b446bc741ee2db3e943ab7e4cabd to your computer and use it in GitHub Desktop.
Convert numpy.datetime64 to datetime.datetime
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)
@gazon1
Copy link

gazon1 commented Jun 10, 2021

Cool! Thanks

@Jggittruth
Copy link

Thanks

@DavidPMika
Copy link

well done, thanks!

@michulcc
Copy link

michulcc commented Mar 1, 2024

Thanks!

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