如何正确获得当前时间另一个城市? [英] How to get current time on another city correctly?

查看:91
本文介绍了如何正确获得当前时间另一个城市?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功地阅读网络服务来获取任意给定市当前时间。
我能得到来自Web服务,当前时间(String)和偏移量。

I have managed to read the web service to get current time of any given city. I could get 2 important values from web service, current time (String) and the offset.

问题
如何正确设置任何城市的时间?

Question is How to set time of any given city correctly?

选项1:


  • 读机/当地时间

  • 计算UTC / GMT时间了机器的时间

  • 市时间= UTC时间+/-偏移值

  • 但是当机时间不准会发生什么?你也将得到
    错误的时间吧?

选项2:


  • 查看当前城市的时间字符串(2012年11月24日19:30)

  • 解析这个时间值,并将其设置为日历

  • 我们得到了正确的城市的时间

  • 又是如何的下一分钟?当然,要求网络服务每分钟获得当前的时间是不是一个好的解决办法吗?是否有可能保持这种日历实例保持运行自动每分钟一次,我们设置呢?

注:我在这里开发Android时钟部件

NB : I'm developing Android clock widget here.

感谢

推荐答案

选项1是更好,在我的眼前。大多数手机有惊人地准确时间作为时间同步是GSM和CDMA的一个组成部分。除此之外,我将远远preFER时钟脱机工作,而不是需要互联网连接。

Option 1 is far better, in my eyes. Most cell phones have amazingly accurate time as time synchronization is an integral part of GSM and CDMA. Beyond that, I would far prefer a clock to work offline than to require internet connectivity.

如果你担心确保在不正确的系统时间,面对的准确性,考虑将调用Web服务来获得当前的时间验证。

If you are worried about ensuring accuracy in the face of incorrect system time, consider placing a call to a web service to get the current time for verification.

这验证可以在后台完成,但要记住,Web服务是不是最好的时间同步提供者。我会让任何与5岁以下的分差去,因为它可能是由于你的服务器不同步或通话时间太长。

This verification could be done in the background, but keep in mind that web services are not the best time sync providers. I would let anything with under 5 minute difference go as it could be due to your server being out of sync or the call taking too long.

这篇关于如何正确获得当前时间另一个城市?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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