Article View: borland.public.cppbuilder.nativeapi
Article #483time.h bug?
From: dave_c
Date: Fri, 14 Mar 2008 14:35
Date: Fri, 14 Mar 2008 14:35
52 lines
2490 bytes
2490 bytes
Hello. I'm having trouble with some time.h functions. the result is different for different c++ builder versions. I have the following code: //--------------------------------------------------------------------- #include "time.h" #include "stdio.h" //... long t = time(0); struct tm *ltime = localtime(&t); char timestr[16]; strftime( timestr, 16 , "%H:%M:%S", ltime); char ResultBuffer[1000]; sprintf(ResultBuffer,"%s (%u) dst=%u", timestr, t,ltime->tm_isdst); Edit1->Text = ResultBuffer; //--------------------------------------------------------------------- When executing this code in Borland C++Builder 6 and Codegear C++Builder 2007 I get different results: C++Builder 6: 14:24:40 (1205501080) dst=0 C++Builder 2007: 14:24:40 (1205497480) dst=1 So the result (in local time) is the same, but I'm using the value from time(0) (which in this case is 1205501080 or 1205497480) to do calculations compared to a time I receive from an external DLL. in C++Builder 6 the time calculation was correct, but in C++ Builder 2007 I get calculation errors of 3600 seconds. It seems that the time(0) function in C++Builder 2007 seems to return the local time, instead of the GMT time? I don't know what has changed in the libraries, so I don't know if a fix now will still work within 6 months or next year. What correction do I have to do to make the calculations work properly? I am in timezone GMT+1:00 (so my _timezone has a value of -3600) Can someone please clarify this for me? Regards, Dave
Technical Details
Message-ID:
<47da8d4e$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng1.kpn.DE!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,63bca7d4c872a25f,start X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Fri, 14 Mar 2008 15:35:16 +0100 From: dave_c <private@email.address> User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: time.h bug? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 194.109.163.251 Message-ID: <47da8d4e$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1205505358 194.109.163.251 (14 Mar 2008 07:35:58 -0700) Lines: 52 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng1.kpn.DE!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail