?? time2.java
字號:
//Time2.java
import java.text.DecimalFormat;
public class Time2 {
private int hour;
private int minute;
private int second;
public Time2(){
setTime( 0, 0, 0 );
}
public Time2( int h, int m, int s ){
setTime( h, m, s );
}
public void setTime( int h, int m, int s ){ //setTime方法
setHour( h );
setMinute( m );
setSecond( s );
}
public void setHour( int h ){ //setHour方法
hour = ( ( h >= 0 && h < 24 ) ? h : 0 );
}
public void setMinute( int m ){ //setMinute方法
minute = ( ( m >= 0 && m < 60 ) ? m : 0 );
}
public void setSecond( int s ){ //setSecond方法
second = ( ( s >= 0 && s < 60 ) ? s : 0 );
}
public int getHour(){ //getHour方法
return hour;
}
public int getMinute(){ //getMinute方法
return minute;
}
public int getSecond(){ // getSecond方法
return second;
}
public String toUniversalString(){
DecimalFormat twoDigits = new DecimalFormat( "00" );
return twoDigits.format( getHour() ) + ":" +
twoDigits.format( getMinute() ) + ":" +
twoDigits.format( getSecond() );
}
public String toStandardString(){
DecimalFormat twoDigits = new DecimalFormat( "00" );
return ( ( getHour() == 12 || getHour() == 0 ) ?
12 : getHour() % 12 ) + ":" + twoDigits.format( getMinute() ) +
":" + twoDigits.format( getSecond() ) +
( getHour() < 12 ? " AM" : " PM" );
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -