的currentTimeMillis()没有返回预期的结果 [英] currentTimeMillis() not returning expected result

查看:125
本文介绍了的currentTimeMillis()没有返回预期的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我需要分析JSON,包括事件的结束时间。当这个事件过程中,我需要计算留给了EVET定稿的时间。要做到这一点,我用这块code的:

In my application, I need to parse a JSON that includes the end time of an event. When this event is in progress, I need to calculate the time left for the finalization of that evet. To do this I use this piece of code:

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

一旦我在几秒钟的时候,我把它转换成D,H,M,S。这是工作像像擎天柱黑色和HTC Desire的一些设备魅力。但今天我测试过我的一个朋友的中兴刀片离开了事件发生时的应用程序是很奇怪的。它出现在负数和数字从原有的非常距离。我测试过不同的值的应用程序,也没有模式,他们就像随机数,例如:

Once I've the time in seconds, I convert it to d,h,m,s. This is working like a charm in some devices like the Optimus Black and the HTC Desire. But today I've tested my app with the ZTE Blade of a friend and the time left of the event is very strange. It appears in negative numbers and digits very distance from the original ones. I've tested the app with different values and there's no pattern, they're like random numbers, e.g:

擎天柱黑色 - >21米32S结果
中兴刀片 - > -38m -57s

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

我认为System.currentTimeMillis的()可以在两个设备不同,但两者都使用CM7作为操作系统。

I've thought that System.currentTimeMillis() could be different in both devices, but both of them are using CM7 as OS.

推荐答案

我觉得问题可能与设备之一诺伊正确设置的时钟。随着时间的提取你给它好像不同的是整整一个小时,这可能是错误的时钟设置的一个原因。当你考虑设定的时间,也看看的时区。这也许是因为两个设备显示相同的时间,但它们中的一个在不同的时间区域中配置

I think the problem might be with the clock of one of the devices noy set properly. With the time extracts you give it seems like the difference is exactly one hour, which might be a cause of wrong clock setting. When you consider the time set, also take a look at the time zone. It might be that both devices show the same time, but one of them is configured in different time zone.

这将是非常怪异的现代设备不能同步时钟中网,但仍有可能对中兴通讯为例。

It will be very weird for modern device not to sync its clock in the net, but still possible for ZTE for example.

这篇关于的currentTimeMillis()没有返回预期的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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