std::chrono örneği: Epoch zaman damgasını chrono'ya dönüştürme ve YYYY-mm-dd olarak biçimlendirme

timestamp_to_date.cpp
double timestamp = 1675917638.773; // Örnek zaman damgası

// Zaman damgasını std::chrono::system_clock::time_point'e dönüştür
auto tp = std::chrono::system_clock::from_time_t(static_cast<time_t>(timestamp));
std::time_t time = std::chrono::system_clock::to_time_t(tp);
std::tm tm = *std::localtime(&time);

// std::tm'yi "YYYY-mm-dd" dizesine biçimlendir
std::ostringstream oss;
oss << std::put_time(&tm, "%Y-%m-%d");
std::string formatted_date = oss.str();

Bu, örneğin 2023-10-09 yazdırır.


Check out similar posts by category: C/C++