Getting system date/time at midnight? 
Author Message
 Getting system date/time at midnight?

Some my users report that when my application is left continuously running
from one day to the next, that the date that is retrieved in my app does not
change when the system clock changes to the next day.  So for example, on
March 22, all is fine, but when midnight rolls around and the software
retrieves the date, it still returns March 22 even though their system clock
has already changed ahead to March 23.  Does anyone see what might be the
trouble?

////////////Get system Date and Time////////////
void Get_DateTime(CString& sztmp, int type)
{

 //modifies incoming param1 as follows:
 //type ==1 means fill with date, type == 2 means fill with time
 //extracts the current system date and time
 //formats date based on user options for date format
 //formats time as hhmm in UTC militry format
 CString Section = "Gen";

 CTime theTime = CTime::GetCurrentTime();
 struct tm* timeptr;  // A pointer to a structure containing time
 timeptr = theTime.GetGmtTm( NULL );

 if(type == FILLDATE)
 {
      switch (AfxGetApp()->GetProfileInt(Section, "DATE", YYYYMMDD))
      {
           case MMDDYYYY:
                     sztmp.Format("%02.2d%02.2d%04.4d",
                      (timeptr->tm_mon)+1, timeptr->tm_mday,
timeptr->tm_year + 1900);
                     break;
           case DDMMYYYY:
                     sztmp.Format("%02.2d%02.2d%04.4d",
                      timeptr->tm_mday, (timeptr->tm_mon)+1,
timeptr->tm_year + 1900);
                     break;

           case YYYYMMDD:
           default:
                     sztmp.Format("%04.4d%02.2d%02.2d",
                      timeptr->tm_year + 1900, (timeptr->tm_mon)+1,
timeptr->tm_mday);
                     break;
       }//end switch
 }//end DATE if

 else //fill with the time
          sztmp.Format("%02.2d%02.2d", timeptr->tm_hour, timeptr->tm_min);

Quote:
}



Thu, 09 Sep 2004 03:43:32 GMT  
 Getting system date/time at midnight?
How often does your app update the date/time display?  Is it perhaps getting the
time a few seconds before midnight, so that date calculations round off to the
previous day, and then not updating right away?


Thu, 09 Sep 2004 15:02:55 GMT  
 Getting system date/time at midnight?
Upon review, I think the problem is more likely that you are calling GetGmtTm,
which gets the date and time at the prime meridian (UTC), which runs through
Greenwich, England.  Unless your users live in that time zone, they will
sometimes see the date change hours from the local change.


Thu, 09 Sep 2004 15:10:01 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. C time/date to Visual Basic time/date

2. Date Time Picker - Date AND Time

3. getting time/date

4. Getting date and time from two 32 bit numbers

5. Need help with getting the system date on the file server

6. Getting Sql database server date and time??

7. Getting a file list based on creation date/time

8. Getting the Date and Time from the Server

9. Getting Date/Time from the Server

10. Getting directory creation date and time???

11. Getting Date/Time in C

12. Getting and Setting System Date

 

 
Powered by phpBB® Forum Software