How to convert NumPy datetime64 to a long ineteger and back?
import numpy as np
import datetime
np.datetime64(datetime.datetime.now()).astype(long)
Gives a value of 1511975032478959
np.datetime64(np.datetime64(datetime.datetime.now()).astype(long))
Gives an error:
ValueError: Converting an integer to a NumPy datetime requires a specified unit
You need to specify the units of the long int (in this case, microseconds).
np.datetime64(np.datetime64(datetime.datetime.now()).astype(long), 'us')
returns
numpy.datetime64('2017-11-29T17:11:44.638713')
'us' converts to microseconds. If you require a different format use:

as shown here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With