I wanted to calculate the time difference for a GMT time and current time. For this I am converting tm time (which is in GMT) to time_t format using mktime. and current time using time() api.
struct tm = x; time_t t1, t2;
time(&t1);
/* here x will get in GMT format */
t2 = mktime(&x);
sec = difftime(t2 , t1);
In this for making the same time zone, is mktime() will take care of converting to local time ? or shall I need to explicitly add sec = difftime(t2 , gmtime(&t1);
Thanks
Yes
mktimeconvert to local time, please read the man:http://www.mkssoftware.com/docs/man3/mktime.3.asp
EDIT : To calculate the difference time between two dates, you can use this