fork(9) download
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5.  
  6. int main( )
  7. {
  8. // current date/time based on current system
  9. time_t now = time(0);
  10.  
  11. // convert now to string form
  12. char* dt = ctime(&now);
  13.  
  14. cout << "The local date and time is: " << dt << endl;
  15.  
  16. // convert now to tm struct for UTC
  17. tm *gmtm = gmtime(&now);
  18. dt = asctime(gmtm);
  19. cout << "The UTC date and time is:"<< dt << endl;
  20. }
Success #stdin #stdout 0.02s 2856KB
stdin
Standard input is empty
stdout
The local date and time is: Mon Jan 14 10:21:32 2013

The UTC date and time is:Mon Jan 14 10:21:32 2013