如何从正在获取的城市获取开放天气API日期/时间?

问题描述 投票:0回答:1

我正在创建一个简单的Weather React应用,并使用Open Weather API。我还将一个外部库用于天气图标。用户输入城市名称,并根据描述使用特定图标获取当前温度。

我的问题是,无法确定是夜晚还是白天,这取决于需要显示的图标。我从获取的城市数据中获得了unix时间戳,但是当我进行转换时,它显示为我的本地时间。还有一个时区偏移,但据我所知不能在Javascript中转换为城市名称。我已经检查过npm软件包,但是找不到。我希望能够获取正在搜索的特定城市的日期/时间,而不是我的本地时间。

我应该继续使用另一个API吗?以下是从伦敦提取的数据:

{coord: {…}, weather: Array(1), base: "stations", main: {…}, visibility: 10000, …}
base: "stations"
clouds: {all: 40}
cod: 200
coord: {lon: -0.13, lat: 51.51}
dt: 1592155233
id: 2643743
main: {temp: 71.8, feels_like: 66.69, temp_min: 71.01, temp_max: 73, pressure: 1014, …}
name: "London"
sys: {type: 1, id: 1414, country: "GB", sunrise: 1592106173, sunset: 1592165939}
timezone: 3600
visibility: 10000
weather: Array(1)
0: {id: 802, main: "Clouds", description: "scattered clouds", icon: "03d"}
length: 1
__proto__: Array(0)
wind: {speed: 9.17, deg: 170}
javascript reactjs npm fetch openweathermap
1个回答
0
投票

我相信您可能会以错误的方式思考。

[您

© www.soinside.com 2019 - 2024. All rights reserved.