Home>

I'm working with api and there was a problem while collecting the date.

Part of the answer:

"priceHistory":[
    {
        "date":1636502400000,
        "price":12200000
    },
    {
        "date":1637193600000,
        "price":12200000
    },
    {
        "date":1637539200000,
        "price":12100000
    },
    {
        "date":1637798400000,
        "price":12000000
    },
    {
        "date":1638403200000,
        "price":12000000
    }
]

What's the logic here? At first I thought that the format was DDMMYYYYHHMiMiSS, but it doesn't fit. The result should be in the format DD/MM/YYYY HH:MiMi:SS.

datetime.datetime.utcfromtimestamp(date/1000)

splash582022-01-29 18:30:44

This is a date in UNIX timestamp/epoch format -the number of milliseconds since 1970-01-01 00:00:00 UTC

MaxU2022-01-29 18:37:44

I'm more than sure that the standard datetime module can turn this into a human-readable format

finally2022-01-29 18:44:54

@finally if only divided by 1000

Namerek2022-01-29 18:51:16

@finally, UNIX timestamp can be in seconds, milliseconds, microseconds and nanoseconds. The standard utcfromtimestamp is designed to work with seconds -for other units you will have to divide by the corresponding number

MaxU2022-01-29 18:55:17