Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CTime

Status
Not open for further replies.

Mongooses

Programmer
Oct 15, 2000
110
US
Hey all,
I have a program that gets the current time by using CTime tmDTG = CTime::GetCurrentTime(); And it worked fine until daylight savings came around now the current time is one hour off. I have tried getting the time by using time.h functions (i.e. using:
time_t tTempTime;
time (&tTempTime);
struct tm * sT;
sT = localtime(&tTempTime);
CTime tmDTG(sT->tm_year + 1900, sT->tm_mon + 1, sT->tm_mday, sT->tm_hour, sT->tm_min, sT->tm_sec, 0);

I have tried using _putenv("TZ=GMT") and have even tried setting each environmental variable (i.e. _timezone, _tzname[0], _tzname[1] and _daylight)

All have returned the time off by 1 hour. There must be a way to get the correct time without resorting to manually adding an hour.

Any help is appreciated,

JC
 
Hmm, it works fine for me. All that these functions do is return the time that your computer clock is set to. Are you sure your clock is correct?
 
Bitwise, after 3 frustrating hours i made sure my time was set correct. A point of contention - the functions do more than return your computer's time. They return a long that is in the number of seconds that have elapsed since 1970 plus they subtract a bias which is the number of seconds that your set timezone differs from GMT and then there is a parameter that determines if daylight saving time is applicable to your timezone. What's even more frustrating is when it works for you :) There are 122 laptops of all brands here and not one of them will return a time not corrected for daylight savings.

WTF, jc
 
Well I found the reason for this apparent aberration and it can be found at The down and dirty is there was a bug in the algorithm that didn't handle 01 Apr falling on a sunday will not recognize daylight savings time until next week. Fear not svc pak 5 came with a fix. I guess I should stay current with the svc pak's since this bug was reported 2 years ago.

HTH,
JC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top