Time zone weather app issue

Hi,

Having this issue with the sunrise and sunset on my weather app:

When user searches for a city outside of Europe, the sunrise doesn’t make any sense, for example the sunrise of Chicago is 1.55pm and the sunrise of L.A. is 3.40pm. Anybody knows why this is? Thanks in advance.

function formatTime(time) {

    let date = new Date(time * 1000);
    let hours = date.getHours();
    let minutes = "0" + date.getMinutes();
    let formattedTime = `${hours}:${minutes.substr(-2)}`;
    return formattedTime;

  }

let sunrise = data.sys.sunrise; //Access sunrise from openweathermap.org, format: 1369769524
let sunset = data.sys.sunset; // Access sunrise from openweathermap.org, format: 1369821049

$('.sunrise').html(`Sunrise <br> ${formatTime(sunrise)}`);
$('.sunset').html(`Sunset <br> ${formatTime(sunset)}`);

Probably because it uses your local time… And since there is a big time difference between Europe and the States you get such weird times.

1 Like