How to get unix timestamp from numpy.datetime64

In order to account for the units, I think you need to do something like:

def get_unixtime(dt64):
    return dt64.astype('datetime64[s]').astype('int')

Note that this converts to ‘seconds’ (the [s]) prior to converting to integers. This works on NumPy 1.12.1.

Leave a Comment