'String timestamp give unrealistic date


I have a ridiculous problem but I can't figure out...
I juste want to convert a timestamp string to a human readable date but the only date I have is completely wrong.
#include <iostream>
#include <string>
#include <stdio.h>
#include <ctime>
int main()
{
    char buf[80];

    std::time_t epoch = std::atol("1645128077111");
    strftime(buf, sizeof(buf), "%d-%m-%Y %H:%M:%S %Z", std::localtime(&epoch));
    std::cout << buf << std::endl;
    // Wanted value is
    // GMT: Thursday 17 February 2022 20:01:17.111
    // OR
    // Your time zone: Thursday 17 February 2022 21:01:17.111 GMT+01:00
}

But my output is 13-01-54102 06:25:11 CET which is completely wrong ! I'm sure is something stupid... But I can't find it so if anybody has the answer I would be grateful.
Thanks for all :)

c++


Solution 1:[1]

Thanks to everyone.

std::time_t epoch = std::atol("1645128077111")/1000;
strftime(buf, sizeof(buf), "%d-%m-%Y %H:%M:%S %Z", std::localtime(&epoch));
std::cout << buf << std::endl;

Give me the correct answer. Dividing by 1000 convert my milliseconds to seconds.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kiki