?? time4.java
字號(hào):
//Time4.java
import java.text.DecimalFormat;
public class Time4 {
private int hour; // 0 - 23
private int minute; // 0 - 59
private int second; // 0 - 59
//5個(gè)重載的構(gòu)造函數(shù)
public Time4(){
setTime( 0, 0, 0 );
}
public Time4( int h ) {
setTime( h, 0, 0 );
}
public Time4( int h, int m ){
setTime( h, m, 0 );
}
public Time4( int h, int m, int s ) {
setTime( h, m, s );
}
public Time4( Time4 time ){
setTime( time.hour, time.minute, time.second );
}
public void setTime( int h, int m, int s ){
hour = ( ( h >= 0 && h < 24 ) ? h : 0 );
minute = ( ( m >= 0 && m < 60 ) ? m : 0 );
second = ( ( s >= 0 && s < 60 ) ? s : 0 );
}
public String toUniversalString(){
DecimalFormat twoDigits = new DecimalFormat( "00" );
return twoDigits.format( hour ) + ":" +
twoDigits.format( minute ) + ":" + twoDigits.format( second );
}
public String toStandardString(){
DecimalFormat twoDigits = new DecimalFormat( "00" );
return ( (hour == 12 || hour == 0) ? 12 : hour % 12 ) + ":" +
twoDigits.format( minute ) + ":" + twoDigits.format( second ) +
( hour < 12 ? " AM" : " PM" );
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -