document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  
  2. /**
  3.  * set time, and convert time to string with formats
  4.  *
  5.  * @author Steve Daniels
  6.  * @version 1.0.1
  7.  */
  8. public class Time1
  9. {
  10.     private int hour;
  11.     private int minute;
  12.     private int second;
  13.    
  14.     //
  15.    
  16.     public void setTime( int h, int m, int s)
  17.     {
  18.         if ( ( h>=0 && h < 24 ) && ( m >= 0 && m < 60 ) &&
  19.         (s >= 0 && s < 60 ) )
  20.         {
  21.             hour = h;
  22.             minute = m;
  23.             second = s;
  24.         } // end if
  25.         else
  26.             throw new IllegalArgumentException (
  27.                 "hour, minute and /or second was out of range" );
  28.     } //end setTime
  29.    
  30.     //convert to String in format HH:MM:SS
  31.     public String toUniversalString()
  32.     {
  33.         return String.format( "%02d:%02d:%02d", hour, minute, second );
  34.     } // end toUniversalString
  35.    
  36.     //convert to string i format H:MM:SS AM/PM
  37.     public String toString()
  38.     {
  39.         return String.format( "%d:%02d:%02d %s",
  40.         ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 ),
  41.         minute, second, ( hour < 12 ? "AM" : "PM" ) );
  42.     }
  43. }
');