Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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"
                        }
                    },
                }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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 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().

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading