I am trying to get UTC time as time_t . The code below seems correct, but surprisingly prints only local time:
time_t mytime; struct tm * ptm; time ( &mytime ); // Get local time in time_t ptm = gmtime ( &mytime ); // Find out UTC time time_t utctime = mktime(ptm); // Get UTC time as time_t printf("\nLocal time %X (%s) and UTC Time %X (%s)", mytime, ctime(&mytime), utctime, ctime(&utctime));
As we can see the values โโof mytime and utctime , we get different. However, when passing ctime parameters ctime it converts them to one line.
Local time is 55D0CB59 (Sun Aug. 16 23:11:45 2015) and UTC 55D07E01 (Sun Aug. 16 23:11:45 2015)
source share