public class Times{
public static void main(String[] args){
int h;
int m;
int s;
int t = 4210;
h =t/3600;
m =(t%3600)/60;
s =(t%3600)%60;
System.out.println(h+"时"+m+"分"+s+"秒");
}
}
给你一个数字 单位是秒,用时分秒显示
帮忙看看这样写对不对
应该怎么做才能显示xx时xx分xx秒希望不吝赐教
public static void main(String[] args){
int h;
int m;
int s;
int t = 4210;
h =t/3600;
m =(t%3600)/60;
s =(t%3600)%60;
System.out.println(h+"时"+m+"分"+s+"秒");
}
}
给你一个数字 单位是秒,用时分秒显示
帮忙看看这样写对不对
应该怎么做才能显示xx时xx分xx秒希望不吝赐教
private int hour;
private int minute;
private int second;
public Time3( int h, int m, int s ){
setTime( h, m, s );
} public Time3(){
this( 0, 0, 0 );
} public Time3( int h ){
this( h, 0, 0 );
} public Time3( int h, int m ){
this( h, m, 0 );
} public Time3( Time3 time ){
this( time.getHour(), time.getMinute(), time.getSecond() );
} public void setTime( int h, int m, int s ){
setHour( h );
setMinute( m );
setSecond( s );
} public void setHour( int h ){
hour = ( ( h >= 0 && h < 24 ) ? h : 0 );
} public void setMinute( int m ){
minute = ( ( m >= 0 && m < 60 ) ? m : 0 );
} public void setSecond( int s ){
second = ( ( s >= 0 && s < 60 ) ? s : 0 );
} public int getHour(){
return hour;
} public int getMinute(){
return minute;
} public int 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" );
}
}
希望这个对你有帮助, 我也是菜鸟 - -
public class Test {
public static void main(String[] args) {
int h;
int m;
int s;
int t = 4206;
h =t/3600;
m =(t%3600)/60;
s =(t%3600)%60;
System.out.println((h<10?"0"+h:h)+"时"+(m<10?"0"+m:m)+"分"+(s<10?"0"+s:s)+"秒");
}
}
String time = twoDigits.format( h ) + "时" + twoDigits.format( m ) + "分" + twoDigits.format( s );