Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
In my software(Built in Visual C++), the displayed time is wrong, i.e it is not updated to the daylight saving time.
I found the function that displays the date and time, but don't know how to put the clock one hour forward !
void CPgInd::OnPoll(double time)
{
  if (m_hWnd)
  {
    CTm80 tm;
    tm = time;
    CString str = tm.Format(_T("%a %d/%m/%Y   %H:%M:%S"));
 
    m_timeStr = str;
    UpdCtrls(); 
  }
}// the format displayed is Thu 03/05/2012 9:46:23

 
Please help
Posted 2-May-12 4:28am
Edited 3-May-12 0:50am
v5
Comments
Schehaider_Aymen at 2-May-12 9:43am
   
what do you mean by update this ? the main function which displays the buttons/edit boxes or the function which displays the "wrong time"?
Member 8446342 at 2-May-12 9:46am
   
Nope I want to know the function that displays the time, so that I can modify to the current GMT....
Schehaider_Aymen at 2-May-12 9:55am
   
I think that You have to locate the variable that is binded the control (which is used to display the time which i presume that it is an edit text) using the class wizard look for that variablle and try to find any call of it in your project; something like var.SetWindowText(....)
Member 8446342 at 2-May-12 10:02am
   
There are just 3 functions with SetWindowText and not time related!:(
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

The Windows API has two functions that return the time of day:
GetSystemTime and GetLocalTime[^].
 
You want to call GetLocalTime. GetSystemTime returns the UTC (Greenwich standard) time. In your meridian, this means you won't get the daylight savings time: in mine, a few hours off.
 
Hope this helps,
 
Pablo.
  Permalink  
Comments
Member 8446342 at 2-May-12 11:36am
   
I didn't quite get that! U mean I must display the local time?
Pablo Aliskevicius at 2-May-12 14:56pm
   
Let's say you move to the West side of the Atlantic. When the 'system time' is noon, the 'local time' may be 8:00 am.
Also, the 'system time' does not provide for daylight savings. The 'local time' is the one you see in the Windows taskbar.
Best wishes,
Pablo.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I cannot quite understand what your problem is but maybe you should be learning about the CRT Time functions[^].
  Permalink  
Comments
Pablo Aliskevicius at 2-May-12 13:25pm
   
I'm a little aprehensive about functions like _localtime64(), that return pointers that it's not clear how or when they should be freed.
Just my two bits...
Richard MacCutchan at 2-May-12 13:46pm
   
If you read the documentation it explains how.
Pablo Aliskevicius at 2-May-12 14:56pm
   
You're right. Seen it now...
Thanks for the hint!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

begin by looking for somthink like This:
 
in the current class (the one which hold the UI)
DDX_Control(pDX, IDC_TIME_ACTIVEX, TIME_VAR);
 
in which
 
* IDC_TIME_ACTIVEX: is the name of the control on the UI.
* TIME_VAR : is the variable Name.
 
Then look for the TIME_VAR Calls you mau find one or more statements by which you display the time is some format.
 
Too, you may find something like :
GetDlgItem(IDC_TIME_ACTIVEX)->SetWindowText(....)
if you find such statement you may look ine the formula passed to that function
  Permalink  
v2
Comments
Member 8446342 at 3-May-12 5:48am
   
At last I found the function that displays the time: But I don't know how to change. The time on software is 1 hour slow.
void CPgInd::OnPoll(double time)
{
if (m_hWnd)
{
CTm80 tm;
tm = time;
CString str = tm.Format(_T("%a %d/%m/%Y %H:%M:%S"));
 
m_timeStr = str;
UpdCtrls();
}
}// the format displayed is Thu 03/05/2012 9:46:23
Richard MacCutchan at 3-May-12 7:09am
   
What is CTm80 and where does your time value come from?
Schehaider_Aymen at 3-May-12 10:17am
   
I Suggest you to use the GetSystemTime function. which retrieves the current system date and time, expressed in UTC.
 

Or you may use GetLocalTime ( as pablo suggested you)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Added +1 to the variable that holds hour.
 
Though this is a temporary solution,(Have to change this when the daylight saving ends) it solves my problem.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

you could use coledatetime stime = coledatetime::getcurrenttime();
noe you could format the stime as per your needs
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 4 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100