Solved

Beginner: CTime and headache

Posted on 2000-04-20
7
344 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  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 …
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

688 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