473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

The output for localtime() is not correct.

I used the localtime() function in the following code snippet:

....
tm = localtime(&ps->date);
printf("---------------------\n");

printf("Date: %d/%02d/%02d %02d:%02d:%02d\n",
1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
....

The printout listed the time one hour off from GMT (probably due to
daylight saving..) instead in local time which is EDT.

The timezone for the platform (Linux Redhat8.0) seems to be setup
correctly. I try to set the TZ with different values, but the results
are for some reason not stable.

Any idea?

Thanks a lot!

David

dz**@sentito.com
Nov 13 '05 #1
3 9421
On 26 Aug 2003 07:18:46 -0700, jd*******@yahoo.com (david) wrote:
tm = localtime(&ps->date);
printf("---------------------\n");

printf("Date: %d/%02d/%02d %02d:%02d:%02d\n",
1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
...
The printout listed the time one hour off from GMT (probably due to
daylight saving..) instead in local time which is EDT.

The timezone for the platform (Linux Redhat8.0) seems to be setup
correctly. I try to set the TZ with different values, but the results
are for some reason not stable.


On the several platforms I have to hand at the moment (none of which are RH
8.0), daylight time offsets appear to be applied to the GMT, not to the
local time.

You may want to check a newsgroup devoted to your compiler and/or platform,
as tzset(), while a popular function, is not part of ANSI/ISO C.

That being said, compare this code with TZ=EST5EDT and TZ=EST5:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
time_t t;
struct tm *gmt, *lat;

tzset();

printf("Local timezone is TZ=%s\n\n", getenv("TZ"));

t = time(NULL);

lat = localtime(&t);
printf("Local time is : %s", asctime(lat));

gmt = gmtime(&t);
printf("GMT is : %s", asctime(gmt));

return 0;
}

Output:

C:\>set tz=EST5EDT

C:\>ltime
Local timezone is TZ=EST5EDT

Local time is : Tue Aug 26 12:27:19 2003
GMT is : Tue Aug 26 16:27:19 2003

C:\>set tz=EST5

C:\>ltime
Local timezone is TZ=EST5

Local time is : Tue Aug 26 12:27:26 2003
GMT is : Tue Aug 26 17:27:26 2003

C:\>
--
Robert B. Clark (email ROT13'ed)
Visit ClarkWehyr Enterprises On-Line at http://www.3clarks.com/ClarkWehyr/
Nov 13 '05 #2
Reply-To: nobody
Followup-To:

On 26 Aug 2003 07:18:46 -0700,
david <jd*******@yahoo.com> wrote:

I used the localtime() function in the following code snippet:

...
tm = localtime(&ps->date);
printf("---------------------\n");

printf("Date: %d/%02d/%02d %02d:%02d:%02d\n",
1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
...

The printout listed the time one hour off from GMT (probably due to
daylight saving..) instead in local time which is EDT.

The timezone for the platform (Linux Redhat8.0) seems to be setup
correctly. I try to set the TZ with different values, but the results
are for some reason not stable.

Any idea?


Your timezone and/or system time isn't set properly, very common. How
to set this is RedHat or linux specific and therefore not a topic
in a C newsgroup.
Villy
Nov 13 '05 #3
On Tue, 26 Aug 2003 13:18:42 -0500,
Robert B. Clark <ep****@3pynexf.pbz> wrote:


On the several platforms I have to hand at the moment (none of which are RH
8.0), daylight time offsets appear to be applied to the GMT, not to the
local time.

UTC time is never influenced by summertime or daylight time, ever.
The local wall clock time may be. BTW GMT is the former name for UTC
and is now used as the name for British standard time.

Whether the system time is running wall clock time or UTC time is
system dependent, and the zone offset is either subtracted from
the local time to get UTC time, or added to the UTC time to get
localtime. This is all system dependent and not a C issue.
Villy
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Roger Leigh | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The program listed below demonstrates the use of wcsftime() and std::time_put<wchar_t> which is a C++ wrapper around it. (I know this isn't C; but...
1
by: KW | last post by:
Hi all, Appreciate if someone can help me out on this. Currently, I have a tm structure holding information of the UTC time, which is very likely to be in the past, meaning not the current...
5
by: Raj | last post by:
Hi I'm very new to C and am trying to get the time a month ago in the format mmyy. What I have tried so far is: char *last_mth; size_t maxsize = 4; struct tm *timeptr = localtime(time(0));
22
by: Merlin | last post by:
Hello everyone, I realize that I'm new to the group, but I'm hoping that someone might be able to help me out. What I'm doing is using the GNU 7zip command line utility to make a backup on my...
1
by: OleMacGeezer | last post by:
Hello Everyone, I am a brand new Python programmer with barely a month of experience under my belt. Here are my specs: Mac OSX Panther 10.3.9 Jython 2.1 implementation with Hermes BBS...
3
by: jonathan184 | last post by:
script is printing output correct but not the actual output. Basically what the script is doing it taking a 1 flat file then it is splits the file into smaller files in 1000 record increments ...
16
by: maruk2 | last post by:
I have some old data files with old timestamps, where timestmap=time(NULL), some of them date back to the year 1999. I want to my code to print the timestamps and each one to include...
1
by: maruk2 | last post by:
I have some old data files with old timestamps, where timestmap=time(NULL), some of them date back to the year 1999. I want my code to print the timestamps and each one to include...
2
by: Devine123 | last post by:
Hi, I’m creating a perl script that takes incoming http/s requests, logs the standard input, output and error, before returning the output to the client. The input, output and error log is appended...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.