如何获取国际标准时间
(2007-10-29 23:53:44) 标签: 知识/探索 | 转自:http://blog.sina.com.cn/s/blog_4ca652f901000cj7.html |
首先想到的便是Webservices,通用,易用。
但是Flash
好了,方法有了,那么Service源呢,这个变难了,找了几个提供Webservices的网站
如:
http://www.webservicex.net/
http://www.webservices.org/
但都未找到这项服务。
继续上网冲浪...
得到了 《获取Nist的美国官方标准时间的解决办法》
作者用的是C#实现的,仔细看了下,用AS3制作貌似差不多。
他使用的是 http://nist.time.gov/timezone.cgi?UTC/s/0先得到标准时间,然后转为北京八区时间。
实际上有更容易的方法,就是将地址中的0换成8,就是东八区的标准时间了,也就是:
http://nist.time.gov/timezone.cgi?UTC/s/8
部分代码:
程序代码
代码中的 rnd="+Math.random()是用来防止Flash读取缓存,得不到最新数据
loadComplete方法中的result就是得到的网页源码,通过字串匹配就可得到时间字符串了.
OK,回过头来接着研究Webservices。找到了 http://www.worldtimeserver.com。
( http://www.worldtimeserver.com/current_time_in_CN.aspx也可以访问这个页,使用上面的方法提取出北京时间)
使用Roading的方法:
程序代码
之所以用“用户名”和“密码”来填充,因为这个站的服务是收费的。
此外,还发现了一个更容易的方法,来测试一下北京奥委会网站: http://time.beijing2008.cn/mtime.php
(不能保证此链接永久有效),嘿嘿,知道怎么用了吧。
再来测试: http://www.time.ac.cn/timeflash.asp?user=flash
返回的是一个XML格式字串,处理起来更为容易些。
这样,目前有四个地址可以得到国际标准时间