java把秒转换成时间
㈠ java 把秒转作 时:分:秒
public class Test{
public static void main(String[] args){
long a=100;
long hour=a/3600; !小时
long minute=a%3600/60; !分钟
long second=a%60; !秒
System.out.println(hour+":"+minute+":"+second);
}
}
㈡ java语言写出:输入一个秒数。转换为小时:分:秒的格式输出。
Java程序:
importjava.util.Scanner;
publicclasstest{
publicstaticvoidmain(String[]args){
Scannerscan=newScanner(System.in);
intnum;
inthour=0;
intminute=0;
intsecond=0;
System.out.print("请输入秒数:");
num=scan.nextInt();
second=num%60;
num-=second;
if(num>0){
num/=60;
minute=num%60;
num-=minute;
if(num>0){
hour=num/60;
}
}
System.out.printf("%d:%d:%d ",hour,minute,second);
}
}
运行测试:
请输入秒数:9876
2:44:36
㈢ 用java怎样把一个以秒为单位的数转换成时分秒,比如说3670s表示为:1时1分10秒 详细的答案给全分!
我刚写的你看看把
public class h
{
public static void main(String args[]){
System.out.print( cal(3670));
}
public static String cal(int second){
int h = 0;
int d = 0;
int s = 0;
int temp = second%3600;
if(second>3600){
h= second/3600;
if(temp!=0){
if(temp>60){
d = temp/60;
if(temp%60!=0){
s = temp%60;
}
}else{
s = temp;
}
}
}else{
d = second/60;
if(second%60!=0){
s = second%60;
}
}
return h+"时"+d+"分"+s+"秒";
}
}