#include <iostream> #include <ctime> int main() { // Define the date and time (e.g., 2022-05-15 09:50:45) tm dateTime = {}; dateTime.tm_year = 2022 - 1900; // Year since 1900 dateTime.tm_mon = 5 - 1; // Month (0-based, so May is 4) dateTime.tm_mday = 15; // Day of the month dateTime.tm_hour = 9; dateTime.tm_min = 50; dateTime.tm_sec = 45; // Convert the tm structure to a Unix timestamp time_t unixTimestamp = mktime(&dateTime); // Print the Unix timestamp std::cout << "Unix Timestamp: " << unixTimestamp << std::endl; return 0; }
tm
tm_year
mktime()
time()
time_t now = time(nullptr);
localtime()
localtime(&now)
gmtime()
gmtime(&now)
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);