gpt4 book ai didi

java - 为什么时间计算不正确?

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

我正在尝试进行简单的时间计算,在文本框中显示耗时。问题是我的方法在应该返回其他值时返回了零值。为此目的是否可以将 long 类型转换为 int 类型?如有任何帮助,我们将不胜感激。

我的代码:

total_hours_paycycle 是一个 long,其值为 259200000。并且在调试器中显示为这样

        try{
int total_minutes = (int) ((total_hours_paycycle/ (1000*60)) % 60); //<--Should return non-zero value, but is returning 0
int total_hours = (int) ((total_hours_paycycle/ (1000*60*60)) % 24); //<--Should return non-zero value, but is returning 0
hours_worked_converted = total_hours + "." + total_minutes; //<--returning 0.0
total_for_paycycle.setText("Total: "+hours_worked_converted + " hrs.");
}catch(Exception e){
total_for_paycycle.setText("Total: - ");
}

最佳答案

为什么不使用android的TimeUnit如果您的 API 级别为 9 及以上,则使用该类:

    int total_minutes = (int)TimeUnit.MILLISECONDS.toMinutes(milliseconds);
int total_hours = (int)TimeUnit.MILLISECONDS.toHours(milliseconds);

关于java - 为什么时间计算不正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19773923/

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