Q:

Write a NumPy program to convert numpy datetime64 to Timestamp

0

Write a NumPy program to convert numpy datetime64 to Timestamp.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
from datetime import datetime
dt = datetime.utcnow()
print("Current date:")
print(dt)
dt64 = np.datetime64(dt)
ts = (dt64 - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')
print("Timestamp:")
print(ts)
print("UTC from Timestamp:")
print(datetime.utcfromtimestamp(ts))

Sample Output:

Current date:                                                          
2017-04-01 08:01:12.722055                                             
Timestamp:                                                             
1491033672.72                                                          
UTC from Timestamp:                                                    
2017-04-01 08:01:12.722055

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now