English 中文(简体)
时值单位未退还预期结果
原标题:currentTimeMillis() not returning expected result
  • 时间:2012-04-09 18:15:32
  •  标签:
  • android

在我的申请中,我需要把包括事件结束时间在内的一名JSON混为一谈。 当这项活动正在进行时,我需要计算完成这一审查所需的时间。 为此,我使用了这一法典:

// I get the time and convert it from millis to seconds
long end = System.currentTimeMillis() / 1000;                      
techsTime.add((int) (queue.event.get("event0").endtime - end));

时间过后,我改为过去。 这在像“最佳的布莱克”和“温和会希望”这样的一些装置中是一种药。 但今天,我与一位好客的兹特·布莱德一道测试了我的看法,而这次活动所留时间非常奇怪。 这个数字是负数,数字与原数字相差很大。 我用不同的价值对 app进行了测试,没有模式,他们像随机数字一样,例如:

Optimus Black -> 21m 32s
ZTE Blade -> -38m -57s

我已想到,该系统在这两种装置中可能有所不同,但两者都使用CM7作为顾问。

最佳回答

我认为,问题可能在于一个装置没有适当安装。 如果你抽出时间,这种区别似乎就好是一小时,这可能会造成错锁。 当你考虑确定的时间时,还要看时区。 这两种装置可能同时显示,但其中一个装置在不同的时间区配置。

现代装置不会把锁在网里,而是仍然有可能,例如ZTE。

问题回答

Use System.nanotime() - it is specially created in order to measure the time between 2 events. System.currentTimeMillis() uses the system clock which does not update every 1 millisecond and thus is unreliable and giving different results.





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签