Advertisement
homer512

Local vs UTC

Feb 3rd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <ctime>
  2. // using std::time, std::gmtime, std::localtime, std::asctime
  3. #include <cstdio>
  4. // using std::printf
  5.  
  6.  
  7. int main()
  8. {
  9.   const time_t now = std::time(nullptr);
  10.   /*
  11.    * Beware the use of global variables and non-reentrant
  12.    * or threadsafe code in the following
  13.    */
  14.   const struct tm localtime = *std::localtime(&now);
  15.   const struct tm utctime = *std::gmtime(&now);
  16.   std::printf("Local: %s", std::asctime(&localtime));
  17.   std::printf("UTC: %s", std::asctime(&utctime));
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement