homer512 icon

Local vs UTC

homer512 | PRO | 02/03/18 09:32:02 AM UTC | 0 ⭐ | 667 👁️ | Never ⏰ | []
C++ |

500 B

|

None

|

0 👍

/

0 👎

#include <ctime>
// using std::time, std::gmtime, std::localtime, std::asctime
#include <cstdio>
// using std::printf
 
 
int main()
{
  const time_t now = std::time(nullptr);
  /*
   * Beware the use of global variables and non-reentrant
   * or threadsafe code in the following
   */
  const struct tm localtime = *std::localtime(&now);
  const struct tm utctime = *std::gmtime(&now);
  std::printf("Local: %s", std::asctime(&localtime));
  std::printf("UTC: %s", std::asctime(&utctime));
}

Comments