I am trying to build a constructor capable of using the current time from the time function as declared in the C++ standard library ( <ctime> ). This constructor should initialize an object of the Time class. Is what I have below going to work?

I guess I need to download Dev C++ again. It won't finish compiling anything right now.

using System;
namespace ThisTest
{
   public class Time : Object
   {
      private int hour;    
      private int minute;  
      private int second;  
      // constructor
      public Time4( int hour, int minute, int second ) 
      { 
         this.hour = hour;
         this.minute = minute;
         this.second = second;
      }
      
      public string BuildString()
      {
         return "this.ToStandardString(): " + 
            this.ToStandardString() + 
            "\nToStandardString(): " + ToStandardString();
      }
      
      public string ToStandardString()
      {
         return String.Format( "{0}:{1:D2}:{2:D2} {3}",
            ( ( this.hour == 12 || this.hour == 0 ) ? 12 : 
            this.hour % 12 ), this.minute, this.second,
            ( this.hour < 12 ? "am" : "pm" ) );
      }      
   }

Recommended Answers

All 2 Replies

I would work better if your code was in C++, and not in CSharp....

Wrong forum

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.