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"
}
},
}
>Solution :
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
Noneor not specified, the timestamp is converted to the platform’s local date and time, and the returneddatetimeobject is naive.
You might want to use utcfromtimestamp() instead, or pass a time zone to fromtimestamp().