- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- time() function dependent on timezone?
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
Discussions
Discussions
Forums
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
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
тАО04-23-2008 10:26 PM
тАО04-23-2008 10:26 PM
I got this query from my programming team. This is a rp3440 system with HP-UX 11.11.
Subject: Unix System clock
Description: In HP-UX the "man 3 time" function call gives following explanation.
Time() returns the time since 00:00:00 GMT, Jan. 1, 1970, measured in seconds. This is the value of the UNIX system clock.
This means number of seconds elapsed since 1/1/1970 00:00:00 irrespective of the timezone /daylight saving.
When I execute the following program HP-UX machine :
main()
{
time_t t;
struct tm ptm;
time(&t)
printf("Timetick %d\n", t);
gmtime_r(&t, &ptm);
printf( "\n 0 gtime %04d-%02d-%02d %02d:%02d:%02d pre-isdst=0\n", ptm.tm_year + 1900,
ptm.tm_mon + 1, ptm.tm_mday, ptm.tm_hour, ptm.tm_min, ptm.tm_sec, ptm.tm_isdst );
localtime_r(&t, &ptm);
printf( "\n 0 local %04d-%02d-%02d %02d:%02d:%02d pre-isdst=0\n", ptm.tm_year + 1900,
ptm.tm_mon + 1, ptm.tm_mday, ptm.tm_hour, ptm.tm_min, ptm.tm_sec, ptm.tm_isdst );
return;
}
Output is when TZ=GMT+4
timetick 1208790892
0 gtime 2008-04-21 15:14:52 pre-isdst=0
0 local 2008-04-21 11:14:52 pre-isdst=0
Output is when TZ=TEST3:30
timetick 1208789056
0 gtime 2008-04-21 14:44:16 pre-isdst=0
0 local 2008-04-21 11:14:16 pre-isdst=0
Information Required:
from the above example time() function does depend on the timezone. Is it TRUE ? Is there any other function which will return number of seconds elapsed since 1970 at GMT+0/UTC. Which should not use the timezone or the daylight configurations.
Useful answers will be rewarded with points.
With regards,
Mohan.
Solved! Go to Solution.
- Tags:
- time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2008 12:51 AM
тАО04-24-2008 12:51 AM
Re: time() function dependent on timezone?
The time() function does not have any relation to timezone setting.
Time is calculated by the number of seconds since January 1, 1970. Time zone merely controls display.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2008 01:18 AM
тАО04-24-2008 01:18 AM
Re: time() function dependent on timezone?
the output from time() (in this case, "t"),
not the output from gmtime_r() or
localtime_r().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2008 01:21 AM
тАО04-24-2008 01:21 AM
Re: time() function dependent on timezone?
Thanks for your reply. In such a case is it not possible to see the time irrespective of the timezone?
From the question I got, I understand that the programmer wants to display the time without the Timezone affecting its display. In other words, how can we display time irrespective of timezone, if possible.
This topic is a bit alien to me and am not sure if I am asking the correct question here.
With regards,
Mohan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2008 01:53 AM
тАО04-24-2008 01:53 AM
Re: time() function dependent on timezone?
time zone settings. I'd expect
localtime[_r]() to depend on the time zone.
man localtime
localtime() Correct for the time zone and any summer time zone
adjustments (such as Daylight Savings Time in the
USA), according to the contents of the TZ
environment variable (see Environment Variables
below). [...]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2008 02:01 AM
тАО04-24-2008 02:01 AM
Re: time() function dependent on timezone?
It is a bit of co-incidence that two Stevens replied to me :-)
I have given your first reply to the people who raised the query. I will post an update based on their response.
I will assign points to you during this update. Thanks for your time.
With regards,
Mohan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2008 02:13 AM
тАО04-24-2008 02:13 AM
Solutionsee a problem with the time() or gmtime_r()
results:
td176> echo $TZ ; ./tt ; export TZ=CST6CDT ; echo $TZ ; ./tt
EST5EDT
Timetick 1209031863
gmtime 2008-04-24 10:11:03 pre-isdst=0
local 2008-04-24 06:11:03 pre-isdst=1
CST6CDT
Timetick 1209031863
gmtime 2008-04-24 10:11:03 pre-isdst=0
local 2008-04-24 05:11:03 pre-isdst=1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2008 02:50 AM
тАО04-24-2008 02:50 AM
Re: time() function dependent on timezone?
Your Last post is encouraging. May I ask you what kind of edit was done on the source? This may solve my problem altogether.
With regards,
Mohan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2008 03:21 AM
тАО04-24-2008 03:21 AM
Re: time() function dependent on timezone?
That's time(2), it is a system call. ctime(3) are a libc functions.
Some minor performance tweaks: time(&t)
Don't do this, it makes the kernel sweat. Instead do:
t = time(NULL);
>printf("Timetick %d\n", t);
The type of time_t is long, so use:
printf("Timetick %ld\n", t);
>how can we display time irrespective of timezone, if possible.
You can't. All times must be relative to some time zone, possibly UTC, unless you want to see the raw time_t decimal number.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2008 06:38 AM
тАО04-24-2008 06:38 AM
Re: time() function dependent on timezone?
Enough to get it through the compiler.
td192> cat tt.c
#include
#include
main()
{
time_t t;
struct tm ptm;
time(&t);
printf("Timetick %d\n", t);
gmtime_r(&t, &ptm);
printf( "gmtime %04d-%02d-%02d %02d:%02d:%02d pre-isdst=%d\n",
ptm.tm_year + 1900, ptm.tm_mon + 1, ptm.tm_mday,
ptm.tm_hour, ptm.tm_min, ptm.tm_sec, ptm.tm_isdst );
localtime_r(&t, &ptm);
printf( "local %04d-%02d-%02d %02d:%02d:%02d pre-isdst=%d\n",
ptm.tm_year + 1900, ptm.tm_mon + 1, ptm.tm_mday,
ptm.tm_hour, ptm.tm_min, ptm.tm_sec, ptm.tm_isdst );
return 0;
}