Skip to content

Instantly share code, notes, and snippets.

@weech
Created September 10, 2018 19:14
Show Gist options
  • Save weech/a0c8397491008a13efd4e637d3ff7682 to your computer and use it in GitHub Desktop.
Save weech/a0c8397491008a13efd4e637d3ff7682 to your computer and use it in GitHub Desktop.
Convert a numpy datetime64 to a python datetime.datetime
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