當前位置:首頁 » 編程語言 » java把秒轉換成時間

java把秒轉換成時間

發布時間: 2024-06-21 09:32:36

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+"秒";
}
}

熱點內容
為什麼車上的伺服器顯示異常 發布:2025-10-17 05:22:46 瀏覽:663
android中spinner 發布:2025-10-17 05:12:56 瀏覽:986
文件上傳ie8 發布:2025-10-17 04:54:55 瀏覽:760
電腦伺服器的地址在哪裡 發布:2025-10-17 04:54:22 瀏覽:400
android加密手機 發布:2025-10-17 04:35:49 瀏覽:428
sql與matlab 發布:2025-10-17 04:35:49 瀏覽:307
車缺少配置有哪些 發布:2025-10-17 04:35:10 瀏覽:64
孕周演算法 發布:2025-10-17 04:35:07 瀏覽:633
c4d添加腳本 發布:2025-10-17 04:35:07 瀏覽:337
synologyftp 發布:2025-10-17 04:33:35 瀏覽:585