By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,463 Members | 774 Online
Bytes IT Community
+ Ask a Question
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

✓ answered by nagarjunasarvepalli

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;

}

Share this Question
Share on Google+
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
  1. time_t diff=(time_t)difftime(l_secs,gmt_secs);
  2. char str[10]  ;
  3. tptr=gmtime(&diff);
  4. strftime(str, 10, "%H %M ",tptr);
  5.  
  6. printf("%s",str);
  7.  
Hoping this works for you.
Sep 7 '10 #5

P: 39
Oh.. and maybe also take a look at:

Expand|Select|Wrap|Line Numbers
  1.  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

Post your reply

Sign in to post your reply or Sign up for a free account.