c - Getting UTC time as time_t -


i trying utc time time_t. code below seems giving correct surprisingly prints local time only:

time_t mytime;  struct tm * ptm;  time ( &mytime ); // local time in time_t  ptm = gmtime ( &mytime ); // find out utc time  time_t utctime = mktime(ptm); // utc time time_t  printf("\nlocal time %x (%s) , utc time %x (%s)", mytime,  ctime(&mytime), utctime, ctime(&utctime)); 

as can see values of mytime , utctime different. however, when passed parameters ctime converts them same string.

local time 55d0cb59 (sun aug 16 23:11:45 2015) , utc time 55d07e01 (sun aug 16 23:11:45 2015)

the ctime result static variable. not use ctime twice in same print statement. in 2 separate print statements.

if ctime replaced asctime, same problem arise asctime returns result static variable.


Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -