1

I am trying to figure out a time format used by someone else. In addition to the date, I have time with an example being the following: 1641859200000

I cant seem to figure out what time or date time format this is. It cannot be HHMMSS, because in this example the second is 85, which is not possible. Any idea what format this is, and how I can convert it using Python to HH:MM:SS ?

Thank you :)

Nathan
  • 11
  • 2
  • I think it would be easier to help if you would be able to provide more examples and some more content in terms of the scale the timestamps might be spread over – user3235916 Jan 30 '22 at 21:46

4 Answers4

1

You have a timestamp in seconds from Epoch since January 1, 1970 (midnight UTC/GMT). To convert to a datetime, use:

from datetime import datetime
print(datetime.fromtimestamp(1641859200000 / 1000))

# Output
2022-01-11 01:00:00

Note: you have to divide by 1000 because this timestamp contains milliseconds and Epoch should be in seconds.

Corralien
  • 109,409
  • 8
  • 28
  • 52
0

This is a Unix-Timestamp.

You can convert in a human-readable format like this:

from datetime import datetime

timestamp = 1641859200000/1000
dt = datetime.fromtimestamp(timestamp)

print(dt)

Edit: didn't check the actual timestamp, whyever, this has to be divided by 1000 as done in the othe answer.

Soaring
  • 13
  • 1
  • 4
0

This probably is a unix timestamp https://en.wikipedia.org/wiki/Unix_time. The factor 1000 stems from a millisecond representation I think. Depends on, from where you got this stamp.

You can convert it using:

>>> datetime.datetime.fromtimestamp(1641859200000/1000)
datetime.datetime(2022, 1, 11, 1, 0)
0

Take a look at dateparser https://dateparser.readthedocs.io/. It will help you figure out what the date and time is based on the range of input date strings:

pip install dateparser
>>> import dateparser
>>> dateparser.parse('1641859200000')
datetime.datetime(2022, 1, 11, 1, 0)

Your timestamp is miliseconds since Unix epoch in this case but if you ever run into similar problem dateparser could help you.


Regarding the second part of the question. Convertion to HH:MM:SS format

>> dt = datetime.datetime(2022, 1, 11, 1, 0)
>> dt.strftime("%H:%M:%S")
'01:00:00'

Additional info: Available Format Codes

Lukasz Wiecek
  • 414
  • 2
  • 8