Converting Milliseconds to Minutes and Seconds?(将毫秒转换为分和秒?)
问题描述
我已经查看了以前的问题,但没有一个答案是我想要的.如何将秒表方法中的毫秒转换为分和秒?我有:
I have looked through previous questions, but none had the answer I was looking for. How do I convert milliseconds from a StopWatch method to Minutes and Seconds? I have:
watch.start();
启动秒表和
watch.stop();
停止手表.我后来有
watch.getTime();
返回毫秒.我希望它在秒和分钟内返回.我该怎么做呢?我正在寻找一种无需乘以/除以 1000 的方法,而是一种使整个计算更具可读性且不易出错的方法.
which returns Milliseconds. I want it to return in Seconds and Minutes. How do I go about doing so? I'm looking for a way to do it without multiplying/dividing by 1000 but rather a method that will make the whole computation more readable and less error-prone.
推荐答案
我建议使用 TimeUnit.你可以这样使用它:
I would suggest using TimeUnit. You can use it like this:
long minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);
这篇关于将毫秒转换为分和秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将毫秒转换为分和秒?
基础教程推荐
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
