Click to See Complete Forum and Search --> : I need help with time


Chronovore
April 21st, 1999, 06:39 AM
I want to take the current date and find the difference between it and a user defined date.
I am pretty new to programming and am going to put this into an MFC dialog application.

Martin vd Berg
April 21st, 1999, 07:02 AM
Have a look at the CTime and CTimeSpan classes.

Martin van den Berg
High Tech Automation
The Netherlands
Martin.van.den.Berg@hta.nl

Joe Farkas
April 21st, 1999, 07:05 AM
You need to use CTime::GetCurrentTime(). You can look the CTime class up in the MSDN library, but this is an example of what I did to get real time using this class in a project
IN THE HEADER FILE********************************************
private:
TerminateDelay *TDelay;
CTime *Time;
CTime osBinaryTime, NextBinaryTime, TargetTime, DisplayTime;
char s[81];
int Sec, Min, Hours, CountDown, CountUp, StartTime, StopTime,
*********************************************************************
IN THE CLASS*********************************************************
osBinaryTime = Time->GetCurrentTime();
Sec = osBinaryTime.GetSecond();
Min = osBinaryTime.GetMinute();
Hours = osBinaryTime.GetHour();
StartTime = ((Hours * 3600) + (Min * 60) + Sec);
StopTime = StartTime + Seconds;
CountDown = StopTime - StartTime;
LastCountDown = CountDown;
while(CountDown > 0)
{
osBinaryTime = Time->GetCurrentTime();
Sec = osBinaryTime.GetSecond();
Min = osBinaryTime.GetMinute();
Hours = osBinaryTime.GetHour();
CountUp = ((Hours * 3600) + (Min * 60) + Sec);
CountDown = StopTime - CountUp;
sprintf(s, "%ld seconds left in %d %s delay", CountDown, Seconds, Message);
if(LastCountDown > CountDown)
{
if(TerminateVoltage > 0)
{
DCVoltage = HP8920.Read(AUDIO_READ_DCV); //READS HARDWARE //Read in the DC Level
if(DCVoltage < TerminateVoltage) //COMPARES VALUE FROM HARDWARE
CountDown = -1; //Indicates that timeout due to voltage drop
}
}
LastCountDown = CountDown;
}

I hope this helps, if you need any more information, you can EMail me.
Joe Farkas
farkas_3@msn.com
farkas-j@grayson.com

Chronovore
April 21st, 1999, 03:17 PM
I'm afraid I may be a little too newbie, but, Which header and which class am I to put these lines of code into?

sally
April 21st, 1999, 09:20 PM
COleDateTime userTime;
// insert a time into the userTime variable

COleDateTimeSpan diff = userTime - COleDateTime::GetCurrentTime();

sally

Sally
April 21st, 1999, 09:20 PM
COleDateTime userTime;
// insert a time into the userTime variable

COleDateTimeSpan diff = userTime - COleDateTime::GetCurrentTime();

sally