Home > database >  convert javascript Date.now to pandas to_datetime
convert javascript Date.now to pandas to_datetime

Time:11-11

I am trying to convert timestamp data that has been fetched with javascript Date.now() and get the date and time into pandas.DataFrame. I am using pandas.to_datetime to convert the timestamp.

However According to the doc The static Date.now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.

so, converting the timestamp 1636460191573 using pd.to_datetime('1636460191573') give Timestamp('1970-01-01 00:27:16.460191573')

How do I get the date and time from the timestamp in dd/mm/yyyy and hh:mm:sec format?

CodePudding user response:

Add parameter unit:

print (pd.to_datetime('1636460191573', unit='ms'))
2021-11-09 12:16:31.573000
  • Related