如何以天显示毫秒:小时:分钟:秒

新手上路,请多包涵

这就是我现在所拥有的

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);

但我的时间和日期不正确

原文由 Akshat Agarwal 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 358
2 个回答

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

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 天的时间,这将有效,但如果您的时间为负值,则无效。

原文由 Peter Lawrey 发布,翻译遵循 CC BY-SA 3.0 许可协议

SimpleDateFormat 是你的朋友! (我今天才发现,太棒了。)

 SimpleDateFormat formatter = new SimpleDateFormat("dd:HH:mm:ss", Locale.UK);

Date date = new Date(timeInMilliSeconds);
String result = formatter.format(date);

原文由 Aurelien Ribon 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题