一個魜D.蓝

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

可以通过网络中一些在线服务,更加经纬度计算此经纬度的时间,api地址和使用格式如: 

 

http://www.earthtools.org/timezone/40.71417/-74.00639

 

 

返回: 

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<timezone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.earthtools.org/timezone-1.1.xsd"> 
  
<version>1.1</version> 
  
<location> 
    
<latitude>40.71417</latitude> 
    
<longitude>-74.00639</longitude> 
  
</location> 
  
<offset>-5</offset> 
  
<suffix>R</suffix> 
  
<localtime>29 Sep 2010 13:44:01</localtime> 
  
<isotime>2010-09-29 13:44:01 -0500</isotime> 
  
<utctime>2010-09-29 18:44:01</utctime> 
  
<dst>Unknown</dst> 
</timezone> 

 

 bugs:上面根据经纬度的api有时候返回的时间是错的,如:san francisco(37.787539,-122.420654)

 通过上面api获取到的时间参见:http://www.earthtools.org/timezone/37.787539/-122.420654

san francisco 真正的当地时间:http://www.timeanddate.com/worldclock/city.html?n=224

 比较发现上面api返回的localtime与真实的时间相差1小时。

 

原因何在?

在这个api中有个dst(Daylight saving time,夏令时,参见:http://baike.baidu.com/view/100246.htm),夏令时比标准时快一小时。

 

如何解决?

如果针对该问题我们可以有很多解决的办法,如去统计哪些地方采用夏令时哪些地方没采用,然后归纳出一个表格,自己提供api。但省时间的方式还是另找新的webservice。

新的api:http://ws.geonames.org/timezoneJSON?lat=37.787539&lng=-122.420654;  它返回一个json格式的数据:{"time":"2010-10-08 09:09","countryName":"United States","sunset":"2010-10-08 18:42","rawOffset":-8,"dstOffset":-7,"countryCode":"US","gmtOffset":-8,"lng":-122.420654,"sunrise":"2010-10-08 07:11","timezoneId":"America/Los_Angeles","lat":37.787539}

time+dstOffset=2:09。 这正是我查询时sfc当地的时间。

 

 

posted on 2010-09-30 02:48  一個魜D.蓝  阅读(5301)  评论(0编辑  收藏  举报