?
Solved

Beginner: CTime and headache

Posted on 2000-04-20
7
Medium Priority
?
348 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

765 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