Weather app sunrise/sunset

Weather app sunrise/sunset
0

#1

I’m in the process of building this app. I want to change the background image based on the user’s weather AND whether it’s day or night where they are. (if it’s clear and night time, I don’t wanna show an image of clear skies during the day). I know the FCC weather API pass through gives us sunrise and sunset time, but it’s for the next day. When I do:

var unixSunrise = result.sys.sunrise;
var sunrise = new Date(unixSunrise*1000);

It gives me tomorrow’s sunrise. Same thing happens with sunset. How do I get the user’s current day’s sunrise and sunset times so that I display the appropriate background image?


#2

i did simply this (by default the clear icon is set as night, the other icons are universal), json it’s the name of the variable that getjson callback function gets

 if (json.dt > json.sys.sunrise && json.dt < json.sys.sunset){
        icoChart["Clear"] = "wi-day-sunny";    
     }

i.e. i used the provided day time

p.s.

I know the FCC weather API pass through gives us sunrise and sunset time, but it’s for the next day.

are you sure? my weather man works i.e. it correctly defines day and night