user16200703
user16200703

Reputation: 47

Python requests timestamp format "timestamp": "1642696349592", what format is this timestamp?

Hello in requests i have a json payload with a timestamp but i cant find out what the timestamp format is, so i don't know how to anwser this request/ make it work.

SO can somebody tell me what the "timestamp" format is? Here is the json payload:

                json = {
                    "pageApiId": "200641",
                    "clientDetails": [],
                    "country": "US",
                    "userAction": "",
                    "source": "PageView",
                    "clientTelemetryData": {
                        "category": "PageView",
                        "pageName": "200641",
                        "eventInfo": {
                        "timestamp": "1642696349592",
                        "enforcementSessionToken": "null",
                        "appVersion": "null",
                        "networkType": "null"
                        }
                    },
                }

Upvotes: 1

Views: 1353

Answers (2)

Chris
Chris

Reputation: 137179

It's probably Unix time in milliseconds. That value corresponds with, roughly, now.

You can create a datetime.datetime object from it using fromtimestamp() like this:

from datetime import datetime

datetime.fromtimestamp(1642696349592 / 1_000)
#=> datetime.datetime(2022, 1, 20, 11, 32, 29, 592000)

Note that the result of the above will be dependent on the machine running this code:

If optional argument tz is None or not specified, the timestamp is converted to the platform’s local date and time, and the returned datetime object is naive.

You might want to use utcfromtimestamp() instead, or pass a time zone to fromtimestamp().

Upvotes: 0

Simon Hawe
Simon Hawe

Reputation: 4539

Seems like a unix timestamp in milliseconds. You can convert that to a human-readable timestamp like datetime.fromtimestamp(1642696349.592) So basically divide it by 1000 to get seconds.

Upvotes: 3

Related Questions