Solved

Beginner: CTime and headache

Posted on 2000-04-20
7
333 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 clear a vector as well as how to detect empty vectors in C++.

863 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

23 Experts available now in Live!

Get 1:1 Help Now