Mega Code Archive

 
Categories / C++ Tutorial / Data Types
 

Convert now to tm struct for UTC

#include <iostream> #include <ctime> #include <cstdlib> using namespace std; int main( ) {   // Current date/time based on current system   time_t now = time(0);    // Convert now to tm struct for UTC   tm* gmtm = gmtime(&now);   if (gmtm != NULL) {      cout << "The UTC date and time is: " << asctime(gmtm) << endl;   }   else {     cerr << "Failed to get the UTC date and time" << endl;     return EXIT_FAILURE;   } } The UTC date and time is: Mon Apr 23 20:17:33 2007