Javascript Date and Time Help

Javascript Date and Time Help
0

#1

I’m on the current weather project and am trying to incorporate the sunrise and sunset times. The jQuery request gives you this format for the time, 1479212760. After looking around I found out how to convert that into “Tue Nov 15 2016 19:01:00 GMT-0500 (Eastern Standard Time),” which isn’t the correct time for the sunrise. Also, it is impossible to find a straight forward way to get just the hours and minutes from that format with JavaScript. Here is the code I’m trying to use, any help would be greatly appreciated, Thanks.

/*Retreiving the OpenWeatherMap date from the jQuery request and converting it into standard long format.*/
  var sunriseDate = Date(value.sys.sunrise);
  /*Getting the hours from the date value*/
  var sunriseHour = sunriseDate.getHour();
  /*Getting the minutes from the date value*/
  var sunriseMinutes = sunriseDate.getMinutes();
  /*Creating the full correct formatted time for sunrise in order to be used later*/
  var sunrise = String(sunriseHour) + ":" + String(sunriseMinutes) + " AM";

#2

Try toLocaleTimeString()


#4

It almost works! It is giving me a time, but it is coming up as 9:54 AM and 9:55 PM instead of 7:25 AM and 5:29 PM where I am. Any thoughts? Here’s a link to it, http://s.codepen.io/NickKatchur/debug/JbodxZ. Also, I know the temperature function doesn’t fully work yet. Thanks.


#6

There we go! Thank you so much!