gpt4 book ai didi

java - 如何将分钟转换为天、小时、分钟

转载 作者:搜寻专家 更新时间:2023-10-30 20:54:43 27 4
gpt4 key购买 nike

如何在 java 中将分钟转换为天小时和分钟(我们这里有一周,7 天)

 public String timeConvert(int time){
String t = "";

int h = 00;
int m = 00;

// h= (int) (time / 60);
// m = (int) (time % 60);

// if(h>=24) h=00;

if((time>=0) && (time<=24*60)){
h= (int) (time / 60);
m = (int) (time % 60);
}else if((time>24*60) && (time<=24*60*2)){
h= (int) (time / (1440));
m = (int) (time % (1440));
}else if((time>24*60*2) && (time<=24*60*3)){
h= (int) (time / (2880));
m = (int) (time % (2880));
}else if((time>24*60*3) && (time<=24*60*4)){
h= (int) (time / (2880*2));
m = (int) (time % (2880*2));
}else if((time>24*60*4) && (time<=24*60*5)){
h= (int) (time / (2880*3));
m = (int) (time % (2880*3));
}else if((time>24*60*5) && (time<=24*60*6)){
h= (int) (time / (2880*4));
m = (int) (time % (2880*4));
}else if((time>24*60*6) && (time<=24*60*7)){
h= (int) (time / (2880*5));
m = (int) (time % (2880*5));
}

t =h+":"+m ;
return t;
}

我试过了,但是不行

谢谢

最佳答案

一条更短的路。 (假设时间 >= 0)

 public String timeConvert(int time) { 
return time/24/60 + ":" + time/60%24 + ':' + time%60;
}

关于java - 如何将分钟转换为天、小时、分钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2751073/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com