473,471 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

4 New Member
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;

}

6 4125
nagarjunasarvepalli
4 New Member
similarly for CDT and GMT it shows 6hrs but actually 5hrs only
Sep 7 '10 #2
MartijnHoekstra
39 New Member
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
nagarjunasarvepalli
4 New Member
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
MartijnHoekstra
39 New Member
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
MartijnHoekstra
39 New Member
Oh.. and maybe also take a look at:

Expand|Select|Wrap|Line Numbers
  1.  tzset();
Sep 7 '10 #6
nagarjunasarvepalli
4 New Member
thanx for the reply,
still same problem
CDT and GMT diff is -5hrs only
but it show -6hrs
Sep 7 '10 #7

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

Similar topics

3
by: Randall Parker | last post by:
Suppose one has a database of UTC times that are from different dates in the past. The problem with translating those times to a local time is that one does not know for each UTC time whether the...
8
by: Henrik Goldman | last post by:
I have strings like "2006-03-26 21.51" which I would like to convert into time_t. I know that the string is in localtime. So far I've written the following code: time_t...
13
by: maflatoun | last post by:
Hi, I have the following function to convert UTC time to Local time. It works perfect for GMT- (Minus) time zones however it provides incorrect results for GMT+(Plus) time zones? // Format to...
3
by: deepeshn | last post by:
Hi people, I have a function which will receive 2 parameters:the date field in GMT time and the user's time zone. I have to return a datetime field in the user's time. the thing is the server...
1
by: princessjewel62 | last post by:
I would like to ask anyone out there, where can I find the "Local Internet Zone" as I had a problem with my application not displaying and saying that I have no authorisation to view this web page...
1
by: dusty | last post by:
I am trying to convert a gmt time which is like 23:00:00 to local time 10:00:00 and even get the time diff that's the offset along with it in c++. Can anyone help me out with this. Thanks a lot in...
1
by: davelist | last post by:
I'm guessing there is an easy way to do this but I keep going around in circles in the documentation. I have a time stamp that looks like this (corresponding to UTC time): start_time =...
2
by: ZR | last post by:
Hello, I need to convert a GMT time string to local time. I can fill out a "tm" structure with the GMT time string. Are there any standard C (or OS) time functions that will allow me to do this? ...
8
by: deepak_kamath_n | last post by:
Hello, I have the following scenario: 1. My application receives the date from another application as a string 2. The other application is running in a different time zone as compared to my...
1
by: Srilathap18783 | last post by:
How to find the difference in Time in SQL with proper Query
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.