I’m using the OpenWeather API to get the sunset time for a specific city. The API returns the sunset time as a UNIX timestamp, and I want to convert this timestamp into the local time of the specific city using JavaScript.
"sys": {
"type": 1,
"id": 5122,
"country": "US",
"sunrise": 1587168307,
"sunset": 1587216456
},
I’ve tried creating a new Date object using the sunset timestamp like this:
var sunsetTimestamp = 1587216456;
var sunsetDate = new Date(sunsetTimestamp);
console.log(sunsetDate)
However, this doesn’t give me the correct local time of sunset.