Reputation: 47
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
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 returneddatetime
object is naive.
You might want to use utcfromtimestamp()
instead, or pass a time zone to fromtimestamp()
.
Upvotes: 0
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