Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 !
C++
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
Updated 2-May-12 23:50pm
v5
Comments
Schehaider_Aymen 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"?
Sumal.V 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 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(....)
Sumal.V 2-May-12 10:02am    
There are just 3 functions with SetWindowText and not time related!:(

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.
 
Share this answer
 
Comments
Sumal.V 2-May-12 11:36am    
I didn't quite get that! U mean I must display the local time?
Pablo Aliskevicius 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.
I cannot quite understand what your problem is but maybe you should be learning about the CRT Time functions[^].
 
Share this answer
 
Comments
Pablo Aliskevicius 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 2-May-12 13:46pm    
If you read the documentation it explains how.
Pablo Aliskevicius 2-May-12 14:56pm    
You're right. Seen it now...
Thanks for the hint!
begin by looking for somthink like This:

in the current class (the one which hold the UI)
C++
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 :
C++
GetDlgItem(IDC_TIME_ACTIVEX)->SetWindowText(....)

if you find such statement you may look ine the formula passed to that function
 
Share this answer
 
v2
Comments
Sumal.V 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 3-May-12 7:09am    
What is CTm80 and where does your time value come from?
Schehaider_Aymen 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)
C#
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.
 
Share this answer
 
you could use coledatetime stime = coledatetime::getcurrenttime();
noe you could format the stime as per your needs
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900