473,748 Members | 6,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.co m
Nov 13 '05 #1
3 9465
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*******@yaho o.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
5213
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 the "problem" lies in the C library implementation of wcsftime()). I'm not sure if this is a platform-dependent feature or part of the C standard. I've compiled with GCC 3.4.3 on GNU/Linux, and run in an en_GB UTF-8
1
24528
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 time. So, let's say I'm in CST(-6) now, and I want to know the equivalent local time of that tm structure, how do I do that taking into consideration daylight savings adjustments?
5
2633
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
2153
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 desktop. Essentially, I'm running an executable that will create a folder, and drop a zipped up copy of my data to that folder. There doesn't seem to be a way to get 7zip to automatically create a file where the filename.zip would be a...
1
4366
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 python module installed
3
1646
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 then it creates another file and adds the header the file contents of the old file. and the file with the header is then renamed to file format i want which is txt.
16
3057
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 hour:minute:second as of the corresponding old day. The only routine for this job seems to be localtime(timestmap) - this is Windows Vista, Visual Studio 2005 C++.
1
1799
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 hour:minute:second as of the corresponding old day. The only routine for this job seems to be localtime(timestmap) - this is Windows Vista, Visual Studio 2005 C++.
2
2098
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 after each HTTP request. The problem I’m having is that I’m trying to add a header line to the log files each time they are appended. For example if a new http request is made, a header will be added to each of the logs before the new standard...
0
8987
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9366
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.