java - 如何以天为单位显示毫秒数 :hours:min:seconds

标签 java android datetime android-calendar

这是我目前拥有的

Seconds = (60 - timeInMilliSeconds / 1000 % 60);
Minutes = (60 - ((timeInMilliSeconds / 1000) / 60) %60);

我觉得是对的。 几个小时和几天应该是这样 -

Hours = ((((timeInMilliSeconds / 1000) / 60) / 60) % 24);
Days =  ((((timeInMilliSeconds / 1000) / 60) / 60) / 24)  % 24;

然后-

TextView.SetText("Time left:" + Days + ":" + Hours + ":" + Minutes + ":" + Seconds);

但我的工作时间和日期显示不正确

最佳答案

计算时间的一种简单方法是使用类似

long seconds = timeInMilliSeconds / 1000;
long minutes = seconds / 60;
long hours = minutes / 60;
long days = hours / 24;
String time = days + ":" + hours % 24 + ":" + minutes % 60 + ":" + seconds % 60; 

如果您有超过 28 天的时间,这将有效,但如果您的时间为负数,则无效。

关于java - 如何以天为单位显示毫秒数 :hours:min:seconds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19667473/

相关文章:

java - inconsolata 和 netbeans

c - 日期/时间格式的纪元时间

json - 在 Play 2.3.7 框架中使用 DateTime

shell - 查找选项 -cmin 和 -amin 之间有什么区别?

java - 我的 java 计算器需要帮助

eclipse - 在 mac os x 上使用 J2SE 6.0 启动 eclipse 时 JVM 终止(需要 J2SE 6.0 for Oracle enterprise pack for eclipse)

android - 隐藏麦克风按钮 Android 虚拟键盘

android - 在外部存储中创建新文件的权限被拒绝

android - 如何在 VideoView 中更改字幕

java - RxJava - 检查条件并仅在条件为真时重复一次