Solved

Beginner: CTime and headache

Posted on 2000-04-20
7
341 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
Industry Leaders: 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 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

749 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