Solved

Beginner: CTime and headache

Posted on 2000-04-20
7
331 Views
Last Modified: 2008-02-26
     CTime time = CTime::GetCurrentTime();
      CTime time2 =( 0, 0, 0, 0, 15, 0 );
      CString m_sTime;
      CString m_sTime2;
      CString m_sTime3;
      m_sTime.Format("%d:%d", time.GetHour(), time.GetMinute());
      m_sTime2.Format("%d:%d", 0, 15);
      
      
      //MessageBox();
      
      
      for (i = 0; i < 16; i++)
      {
            MoveTo(X1 + i * xOffset, Y1);      
            LineTo(X1 + i * xOffset, Y1 - lineWidth);
            
            ASSERT(( m_sTime - m_sTime2 ) == m_sTime );  
      
}
VISUAL C++ 6:
what i am trying to do is to set two times. One the system time and the second 15 minutes. This is ok (checking it by MessageBox(); (is there an easier way to show values while programming ?)
Now i would like to substract the 15 minutes from the system time 15 times. so for example 15:00 --> 14:45 --> 14:30

I fail comletely as m_stime is empty. The substraction is not made.

I am confused :/
0
Comment
Question by:peter_b
  • 5
  • 2
7 Comments
 

Author Comment

by:peter_b
ID: 2736243
ASSERT(( m_sTime - m_sTime2 ) == m_sTime );  
is of course ASSERT(( m_sTime - m_sTime2 ) == m_sTime3 );

still m_sTime3 is empty  
0
 

Author Comment

by:peter_b
ID: 2736303
for (i = 0; i < 16; i++)
      {
            MoveTo(X1 + i * xOffset, Y1);      
            LineTo(X1 + i * xOffset, Y1 - lineWidth);
            m_sTime.Format("%d:%d", time.GetHour(), time.GetMinute()- 15*i);
            
            if (i > 0)
            {
                  
                  s.Format(m_sTime);
                  
                  TextOut(X1 + i * xOffset - xOffset/ 2, Y1 - lineWidth, s);
            }
      }

ok the minutes count down but to minus. How can i make the hours adapt and prevent minutes of getting minus ??
0
 

Author Comment

by:peter_b
ID: 2736306
for (i = 0; i < 16; i++)
      {
            MoveTo(X1 + i * xOffset, Y1);      
            LineTo(X1 + i * xOffset, Y1 - lineWidth);
            m_sTime.Format("%d:%d", time.GetHour(), time.GetMinute()- 15*i);
            
            if (i > 0)
            {
                  
                  s.Format(m_sTime);
                  
                  TextOut(X1 + i * xOffset - xOffset/ 2, Y1 - lineWidth, s);
            }
      }

ok the minutes count down but to minus. How can i make the hours adapt and prevent minutes of getting minus ??
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:peter_b
ID: 2736308
for (i = 0; i < 16; i++)
      {
            MoveTo(X1 + i * xOffset, Y1);      
            LineTo(X1 + i * xOffset, Y1 - lineWidth);
            m_sTime.Format("%d:%d", time.GetHour(), time.GetMinute()- 15*i);
            
            if (i > 0)
            {
                  
                  s.Format(m_sTime);
                  
                  TextOut(X1 + i * xOffset - xOffset/ 2, Y1 - lineWidth, s);
            }
      }

ok the minutes count down but to minus. How can i make the hours adapt and prevent minutes of getting minus ??
0
 
LVL 1

Accepted Solution

by:
MT_MU earned 50 total points
ID: 2736335
CTime holds not only the current time but the date as well.

In your example "time" is the the current date and time.

Although I'm having a little trouble deciphering your example, you could in general do something like...


      CTime time = CTime::GetCurrentTime();
      CTimeSpan MinutesX15 = CTimeSpan(0,0,15,0);

      CString display_time;
      for (int i = 1; i < 15;i++)
      {
        time -= MinutesX15;
        display_time = time.Format("%H:%M");
 
      }
0
 

Author Comment

by:peter_b
ID: 2736400
May I call you the rescue before midnight ?

Thank you very much !
0
 
LVL 1

Expert Comment

by:MT_MU
ID: 2736407
You can call me whatever you'd like. <g>
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now