- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: calculating timezone difference on HP-UX
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2007 06:42 PM
05-14-2007 06:42 PM
In my program I need to find out the difference in time zones from UTC to local time zone.
For this I use the following code:
==================================
// get the system time
time((time_t*)&long_time);
// Get the GM time
ptime = gmtime(&long_time);
ptime->tm_isdst= -1 ;
long_timegm = mktime(ptime);
// get the local time
ptime = localtime(&long_time);
ptime->tm_isdst= -1 ;
long_timelocal = mktime(ptime);
// calculate the difference in timezones in terms of hours
timezone = long_timelocal - long_timegm;
m_timezone = (float)timezone/3600;
printf("Timezone off set in hours is : %f\n",m_timezone);
=========================================
The above programs behaviour is different with different values of TZ environment variable.
When TZ is set to IST (which is GMT+5:30), the timezone printed with above program is ZERO. Which is incorrect.
When the TZ is set to GMT+5:30, the value printed is -5.5 which is correct (IST = GMT + 5: 30)
When TZ is set to GMT, the value printed is again ZERO.
I am unable to understand the behaviour of the program. Can someone explain me whats wrong with this code ?
Thanks in advance,
Ravi Nandibhatla.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2007 08:33 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2007 08:36 PM
05-14-2007 08:36 PM
Re: calculating timezone difference on HP-UX
Thank you for the reply.
Could you please tell me whether the logic I am using to calculate the time difference between UTC to local time is correct or not ?
Thanks,
Ravi Nandibhatla.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2007 09:04 PM
05-14-2007 09:04 PM
Re: calculating timezone difference on HP-UX
Well mktime(3) says it takes the local time. So you are misusing mktime and may cause problems during the DST transitions.
Instead of doing all of that coding, you can simplify it to:
tzset();
printf("the value of timezone is: %f\n", (double)timezone/3600);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2007 09:14 PM
05-14-2007 09:14 PM
Re: calculating timezone difference on HP-UX
I could not follow your response. How did you get the timezone value so that we can divide it by 3600 ?
Also the man page indicates that tzset() will be called automatically whenever we call functions like localtime, mktime, ctime etc.
Thanks,
Ravi Nandibhatla.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2007 09:31 PM
05-14-2007 09:31 PM
Re: calculating timezone difference on HP-UX
When you call tzset(), timezone is automatically set.
>Also the man page indicates that tzset() will be called automatically whenever we call functions like localtime, mktime, ctime etc.
Yes but my "example" ONLY had tzset and the printf of timezone.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 09:52 PM
05-16-2007 09:52 PM
Re: calculating timezone difference on HP-UX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 09:53 PM
05-16-2007 09:53 PM
Re: calculating timezone difference on HP-UX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 10:07 PM
05-16-2007 10:07 PM
Re: calculating timezone difference on HP-UX
http://forums1.itrc.hp.com/service/forums/helptips.do?#33
You can reopen it with:
http://forums1.itrc.hp.com/service/forums/helptips.do?#41
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2007 03:52 PM
05-20-2007 03:52 PM