#include <iostream> #include <ctime> int main() { // Unix timestamp representing the number of seconds since the Unix epoch time_t unixTimestamp = 1652642245; // Convert Unix timestamp to a tm structure (UTC) tm *dateTime = gmtime(&unixTimestamp); // Print the converted date and time std::cout << "Converted Date: " << dateTime->tm_year + 1900 << "-" << dateTime->tm_mon + 1 << "-" << dateTime->tm_mday << " " << dateTime->tm_hour << ":" << dateTime->tm_min << ":" << dateTime->tm_sec << std::endl; return 0; }
gmtime()
tm
tm_year
tm_mon
localtime()
time()
time_t now = time(nullptr);
localtime(&now)
gmtime(&now)
mktime()
time_t timestamp = mktime(&tm_struct);
strftime()
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &tm_struct);
difftime()
double diff = difftime(time1, time2);
asctime()
asctime(&tm_struct)
ctime()
ctime(&now)
std::chrono::system_clock::now()
std::chrono::time_point
auto now = std::chrono::system_clock::now();
std::chrono::duration_cast()
std::chrono::duration_cast(duration);