Python请求时间戳格式"timestamp":“1642696349592”,这个时间戳是什么格式?
Python requests timestamp format "timestamp": "1642696349592", what format is this timestamp?
你好,在请求中,我有一个带有时间戳的 json 有效载荷,但我无法找出时间戳格式是什么,所以我不知道如何回答这个请求/使其工作。
有人能告诉我“时间戳”格式是什么吗?
这是 json 有效载荷:
json = {
"pageApiId": "200641",
"clientDetails": [],
"country": "US",
"userAction": "",
"source": "PageView",
"clientTelemetryData": {
"category": "PageView",
"pageName": "200641",
"eventInfo": {
"timestamp": "1642696349592",
"enforcementSessionToken": "null",
"appVersion": "null",
"networkType": "null"
}
},
}
可能是 Unix time 毫秒。该值大致对应于现在。
您可以使用 fromtimestamp()
从它创建一个 datetime.datetime
对象,如下所示:
from datetime import datetime
datetime.fromtimestamp(1642696349592 / 1_000)
#=> datetime.datetime(2022, 1, 20, 11, 32, 29, 592000)
注意上面的结果将取决于机器运行这段代码:
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.
您可能想改用 utcfromtimestamp()
,或将时区传递给 fromtimestamp()
。
似乎是一个以毫秒为单位的 unix 时间戳。您可以将其转换为 human-readable 时间戳,例如
datetime.fromtimestamp(1642696349.592)
所以基本上除以 1000 得到秒。
你好,在请求中,我有一个带有时间戳的 json 有效载荷,但我无法找出时间戳格式是什么,所以我不知道如何回答这个请求/使其工作。
有人能告诉我“时间戳”格式是什么吗? 这是 json 有效载荷:
json = {
"pageApiId": "200641",
"clientDetails": [],
"country": "US",
"userAction": "",
"source": "PageView",
"clientTelemetryData": {
"category": "PageView",
"pageName": "200641",
"eventInfo": {
"timestamp": "1642696349592",
"enforcementSessionToken": "null",
"appVersion": "null",
"networkType": "null"
}
},
}
可能是 Unix time 毫秒。该值大致对应于现在。
您可以使用 fromtimestamp()
从它创建一个 datetime.datetime
对象,如下所示:
from datetime import datetime
datetime.fromtimestamp(1642696349592 / 1_000)
#=> datetime.datetime(2022, 1, 20, 11, 32, 29, 592000)
注意上面的结果将取决于机器运行这段代码:
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.
您可能想改用 utcfromtimestamp()
,或将时区传递给 fromtimestamp()
。
似乎是一个以毫秒为单位的 unix 时间戳。您可以将其转换为 human-readable 时间戳,例如
datetime.fromtimestamp(1642696349.592)
所以基本上除以 1000 得到秒。