#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