Convert now to tm struct for UTC : time « Data Types « C++ Tutorial






#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








2.33.time
2.33.1.Displays the current date and time
2.33.2.Show standard time and date string
2.33.3.Show a custom time and date string
2.33.4.%c specifies the standard time and date pattern
2.33.5.The strftime( ) Format Specifiers
2.33.6.Convert now to tm struct for UTC
2.33.7.Set the locale to US and get the time_put facet for US
2.33.8.Set the locale to Germany, Show standard time and date string
2.33.9.custom pattern displays hours and minutes followed by the date
2.33.10.Set the locale to Germany and get the time_put facet for Germany
2.33.11.Demonstrating the use of the localtime( ) and asctime( ) functions.
2.33.12.Demonstrating the use of the gmtime( ) and asctime( ) functions.
2.33.13.use of the strftime( ) function.
2.33.14.Demonstrating the use of the ctime( ) function.
2.33.15.Convert now to tm struct for local timezone