432,463 Members | 774 Online
Need help? Post your question and get tips & solutions from a community of 432,463 IT Pros & Developers. It's quick & easy.

# how to find the time difference between GMT and Local time zone

 P: 4 i was follow one procedure,by using mktime and gmtime functions but it is showing wrong answer.. example 1)Diff between IST and GMT 5:30 by using the aboue functions it showing 5:50 Sep 7 '10 #1

thanx for the response..

0.5 * 100 instead of 0.5 * 60 = 30 may be this will happen for IST but wat about CDT instead of 5 it gives 6hrs

ok this is the sourse code..

int main() {
struct tm *tptr;
time_t secs,l_secs,gmt_secs;
float diff;
time(&secs);

tptr = localtime(&secs);
l_secs=mktime(tptr);
tptr=gmtime(&secs);
gmt_secs=mktime(tptr);
diff=l_secs-gmt_secs;

printf("difff %f",diff/3600.0);

return 1;

}

6 Replies

 P: 4 similarly for CDT and GMT it shows 6hrs but actually 5hrs only Sep 7 '10 #2

 P: 39 Can you post your sources? I have rough feeling that the minutes are shown in 0.5 * 100 instead of 0.5 * 60 = 30 Sep 7 '10 #3

 P: 4 thanx for the response.. 0.5 * 100 instead of 0.5 * 60 = 30 may be this will happen for IST but wat about CDT instead of 5 it gives 6hrs ok this is the sourse code.. int main() { struct tm *tptr; time_t secs,l_secs,gmt_secs; float diff; time(&secs); tptr = localtime(&secs); l_secs=mktime(tptr); tptr=gmtime(&secs); gmt_secs=mktime(tptr); diff=l_secs-gmt_secs; printf("difff %f",diff/3600.0); return 1; } Sep 7 '10 #4

 P: 39 the best way to find difference is to use: difftime also you can just make diff a time_t type. Then to display the difference exactly, you can make use of the gmtime function and strftime to display. See example: Expand|Select|Wrap|Line Numbers time_t diff=(time_t)difftime(l_secs,gmt_secs); char str[10]  ; tptr=gmtime(&diff); strftime(str, 10, "%H %M ",tptr);   printf("%s",str);   Hoping this works for you. Sep 7 '10 #5

 P: 39 Oh.. and maybe also take a look at: Expand|Select|Wrap|Line Numbers  tzset(); Sep 7 '10 #6

 P: 4 thanx for the reply, still same problem CDT and GMT diff is -5hrs only but it show -6hrs Sep 7 '10 #7