📄 time4.java
字号:
//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个重载的构造函数
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" );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -