You can start by using an istringstream
or std::stoll
to convert the hex timestamp:
#include <chrono>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
int main() {
std::string timeString = "00059f4d1832788e";
std::istringstream is(timeString);
long long x;
is >> std::hex >> x; // x now contains the value
// or:
// long long x = std::stoll(timeString, nullptr, 16);
// then convert it to a chrono::time_point:
std::chrono::microseconds us(x);
std::chrono::time_point<std::chrono::system_clock> sc(us);
// and finally convert the time_point to time_t
std::time_t t_c = std::chrono::system_clock::to_time_t(sc);
// and print the result
std::cout << std::put_time(std::gmtime(&t_c), "%FT%TZ") << '\n';
std::cout << std::put_time(std::localtime(&t_c), "%FT%T%z (%Z)") << '\n';
}
Possible output:
2020-02-24T07:12:30Z
2020-02-24T08:12:30+0100 (CET)