Android:带有毫秒的计时器? [英] Android: Chronometer with Milliseconds?

查看:1404
本文介绍了Android:带有毫秒的计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的是以毫秒为单位测量时间,但是使用Chronometer却存在精度不高的问题(其最高分辨率为秒) 我已经看到了: 使用Android Chronometer显示毫秒 但是我无法使其工作.也许我应该使用另一个对象?有什么主意吗?

What I want is to measure time with milliseconds, but using Chronometer has the problem that it has no accuracy (its most resolution is seconds) I've seen this: Show miliseconds with Android Chronometer But I haven't been able to make it work. Maybe I should use another Object? Any idea?

推荐答案

好,这是最简单的方法:当您要启动计时功能时:

Ok, this is the easiest way: When you want to start the chrono:

StartTime=System.currentTimeMillis(); // I've defined StartTime as a double

然后,您只需要将当前时间与StartTime进行比较:

Then, you just have to do compare current time with StartTime:

millis=System.currentTimeMillis()-StartTime; // Millis is a double too
// If you'd want seconds, add seconds=(int) milis/1000; etc.

这样您就可以玩milis(到达我想要的时间了吗?它要数多少时间?...)

And so you can play with milis (Has it arrive to the time I wanted? How many time is it counting? ...)

这篇关于Android:带有毫秒的计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆