CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 1999
    Location
    Michigan, USA
    Posts
    29

    I need help with time

    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.


  2. #2
    Join Date
    Apr 1999
    Posts
    42

    Re: I need help with time

    Have a look at the CTime and CTimeSpan classes.

    Martin van den Berg
    High Tech Automation
    The Netherlands
    [email protected]

  3. #3
    Join Date
    Sep 1999
    Location
    Virginia
    Posts
    5

    Re: I need help with time

    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
    [email protected]
    [email protected]



  4. #4
    Join Date
    Apr 1999
    Location
    Michigan, USA
    Posts
    29

    Re: I need help with time

    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?


  5. #5
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: I need help with time

    COleDateTime userTime;
    // insert a time into the userTime variable

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

    sally




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured