无法使用forecast.io API获取当前时间预测

时间:2016-01-01 04:03:36

标签: java android

我正在使用forecast.io服务构建一个简单的天气Android应用程序。

使用

的默认调用
https://api.forecast.io/forecast/<my_key>/37.8136,144.9631?units=auto

似乎总是在我不关心的时候给我预测 - 也就是说,它目前在这里是2.40PM,它一直给我3.40AM的预测。

所以我接着尝试使用时间参数,但它仍然给我3.40AM,而不是2.40PM

https://api.forecast.io/forecast/<my_key>/37.8136,144.9631,1451619638?units=auto

我已通过有用的网站http://www.epochconverter.com/

验证1451619638作为当前的unix时间

关于为什么我似乎无法获得当地当地时间的任何指示?

1 个答案:

答案 0 :(得分:1)

API返回时区,然后返回GMT的偏移量。检查那些。

第一个想法是,如果你没有提供时间,你将获得当前的预测,你所要做的就是将它转换成你的时区。因此,如果他们正在做GMT并且您是GMT - 8,那么您只需从时间值中减去8。

两个领域都在那里:

latitude: The requested latitude.
longitude: The requested longitude.
timezone: The IANA timezone name for the requested location (e.g. America/New_York). This is the timezone used for text forecast summaries and for determining the exact start time of daily data points. (Developers are advised to rely on local system settings rather than this value if at all possible: users may deliberately set an unusual timezone, and furthermore are likely to know what they actually want better than our timezone database does.)
offset: The current timezone offset in hours from GMT.

我一直在使用这个API。