Click to See Complete Forum and Search --> : problem with changing dynamically a clock.


Green Fuze
April 8th, 2005, 08:57 PM
I have created a clock with:

CTime curTime = CTime::GetCurrentTime();

and

m_sTime = curTime.Format("%H:%M"); //m_sTime is a string of a static text

and it works great!!!

B-U-T

the thing is that I want it to add or subtract hours by the value of an integer
(or anything else that might do the job).

I thought maybe to add curTime.getHour() and the request integer (that should represent GMT) and than to convert the whole thing to a string,
but I'm having troubles in that to (the .ToString() doesn't really work...),
but I'd still have a problem that the hour of 23:13 in GMT+1 in GMT+3 will become 25:13, instead of 01:13.

is there any normal, not-so-complicated way to do that? and if not, can anyone help me with the int to string conversion.

THANKS ALOT!!

Siddhartha
April 9th, 2005, 11:40 AM
Look up COleDateTime (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_coledatetime.asp)

You can use the operators + and - (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_coledatetime.asp) with a COleDateTimeSpan (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_coledatetimespan.asp) object to perform additions and substractions.

Of course, your project needs MFC support to use this.

can anyone help me with the int to string conversion.
Use - _itoa (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__itoa.2c_._i64toa.2c_._ui64toa.2c_._itow.2c_._i64tow.2c_._ui64tow.asp)

Green Fuze
April 9th, 2005, 01:45 PM
thanks :-)
I'll check it out...

Green Fuze
April 9th, 2005, 08:31 PM
works great!
thanks! :-)

Siddhartha
April 10th, 2005, 05:23 AM
works great!
thanks! :-)
You are welcome. ;)