gpt4 book ai didi

java - 如何将以秒为单位的时间转换为完整时间戳?

转载 作者:行者123 更新时间:2023-12-01 07:01:10 25 4
gpt4 key购买 nike

我在将时间1352364(以秒为单位)转换为“周、天、小时、秒、分钟”的时间戳格式时遇到问题。这是到目前为止我的代码。

int timeToGrow = 1352364;
int secs = timeToGrow % 60;
int mins = (timeToGrow / 60) % 60;
int hours = (timeToGrow / 60) / 60;
int days = ((timeToGrow / 60) / 60) / 24;
int weeks = (((timeToGrow/60)/60)/24)/7;

System.out.println(weeks + " Weeks "+ days + " Days " + hours + " Hours " + mins + " Minutes " + secs + " Seconds.");

代码应该打印出2 Weeks 1 Days 15 Hours 39 Minutes 24 Seconds,但实际上却打印出2 Weeks 15 Days 375 Hours 39 Minutes 24 Seconds。我想我看到了这个问题,但我不知道如何解决它。请原谅我的措辞不佳,但我认为小时部分包括天和周部分中的时间,不像时间是分开的,比如分钟和秒(再次抱歉,我不知道如何措辞)。如何更改公式以正确显示正确的时间戳?非常感谢!

最佳答案

int timeToGrow = 1352364;
int secs = timeToGrow % 60;
int mins = (timeToGrow / 60) % 60;
int hours = ((timeToGrow / 60) / 60) % 24;
int days = (((timeToGrow / 60) / 60) / 24) % 7;
int weeks = (((timeToGrow/60)/60)/24)/7;
System.out.println(weeks + " Weeks "+ days + " Days " + hours + " Hours " + mins + " Minutes " + secs + " Seconds.");

关于java - 如何将以秒为单位的时间转换为完整时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49885747/

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