I am using the Weather APi found here: http://openweathermap.org/
The Sunrise and Sunset come back as numerical objects such as :
I have tried all the methods i could find, but still no luck, as the majority of methods are looking for a complete UTC date, not just a UTC Time.
How can i convert this with javascript, into the user's local time zone?
If all you want is local time (no date info) then Leo is right. I had incorrectly stated milliseconds but unix tick units are actually seconds so we must multiply by 1000 to construct a correct javascript Date.
var sec = 1425909686;
var date = new Date(sec * 1000);
var timestr = date.toLocaleTimeString();
console.log(date, timestr);
$("#d1").html(date);
$("#d2").html(timestr);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="d1"></div>
<div id="d2"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With