2011-06-12 28 views
2

我使用谷歌API獲取天氣,並在響應我也獲得當地時間,但它是遠離,而不是正確的時間。當地時間從免費的API

有沒有Google的時間api或其他免費的東西?

這是我現在使用:

http://www.google.com/ig/api?weather=hong kong 

    <?xml version="1.0" ?> 
- <xml_api_reply version="1"> 
- <weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0"> 
- <forecast_information> 
     <city data="hong kong" /> 
     <postal_code data="hong kong" /> 
     <latitude_e6 data="" /> 
     <longitude_e6 data="" /> 
     <forecast_date data="2011-06-12" /> 
     <current_date_time data="2011-06-12 22:30:00 +0000" /> 
     <unit_system data="US" /> 
    </forecast_information> 
- <current_conditions> 
     <condition data="Partly Cloudy" /> 
     <temp_f data="86" /> 
     <temp_c data="30" /> 
     <humidity data="Humidity: 70%" /> 
     <icon data="/ig/images/weather/partly_cloudy.gif" /> 
     <wind_condition data="Wind: S at 12 mph" /> 
    </current_conditions> 
- <forecast_conditions> 
     <day_of_week data="Sun" /> 
     <low data="81" /> 
     <high data="84" /> 
     <icon data="/ig/images/weather/chance_of_rain.gif" /> 
     <condition data="Chance of Rain" /> 
    </forecast_conditions> 
- <forecast_conditions> 
     <day_of_week data="Mon" /> 
     <low data="81" /> 
     <high data="84" /> 
     <icon data="/ig/images/weather/mostly_sunny.gif" /> 
     <condition data="Partly Sunny" /> 
    </forecast_conditions> 
- <forecast_conditions> 
     <day_of_week data="Tue" /> 
     <low data="81" /> 
     <high data="84" /> 
     <icon data="/ig/images/weather/chance_of_storm.gif" /> 
     <condition data="Chance of Storm" /> 
    </forecast_conditions> 
- <forecast_conditions> 
     <day_of_week data="Wed" /> 
     <low data="81" /> 
     <high data="84" /> 
     <icon data="/ig/images/weather/chance_of_storm.gif" /> 
     <condition data="Chance of Storm" /> 
    </forecast_conditions> 
    </weather> 
    </xml_api_reply> 
+0

這不是當地時間。如果您看到時間爲「2011-06-12 22:30:00 +0000」,其中+0000代表GMT +00:00您可以通過添加偏移量將其轉換爲當地時間。 – Codevalley 2011-11-08 09:48:28

+0

哪裏可以得到偏移量?它不在返回的xml中 – 2011-11-08 14:27:06

回答

1

這不是當前的時間。這是該地點的上次天氣更新的日期和時間。你會注意到,隨着時間的推移(在一個常數),返回的值保持不變。

你不需要一個API來獲取某人電腦的本地時間。只要問問他們自己。

<script language='javascript' > 
var currentTime = new Date() 
var hours = currentTime.getHours() 
var minutes = currentTime.getMinutes() 
document.write("<b>" + hours + ":" + minutes + " " + "</b>") 
</script> 

或者如果這是在服務器上,只需使用您的編程語言向服務器詢問當地時間。

+0

我笑着問自己,但無論如何,這似乎是唯一的方法。 +1 – 2012-02-20 07:56:56