admin管理员组文章数量:1313267
I am using the Weather APi found here: /
The Sunrise and Sunset e back as numerical objects such as :
- 1425951068 (sunset okotoks, ab, can)
- 1425909686 (sunrise okotoks, ab, can)
I have tried all the methods i could find, but still no luck, as the majority of methods are looking for a plete UTC date, not just a UTC Time.
How can i convert this with javascript, into the user's local time zone?
I am using the Weather APi found here: http://openweathermap/
The Sunrise and Sunset e back as numerical objects such as :
- 1425951068 (sunset okotoks, ab, can)
- 1425909686 (sunrise okotoks, ab, can)
I have tried all the methods i could find, but still no luck, as the majority of methods are looking for a plete UTC date, not just a UTC Time.
How can i convert this with javascript, into the user's local time zone?
Share Improve this question edited Mar 11, 2015 at 1:05 ayla asked Mar 9, 2015 at 22:00 aylaayla 3,54612 gold badges50 silver badges75 bronze badges 5- What's your desired output? – Leo Commented Mar 11, 2015 at 1:16
-
Use javascript
Date
API. Those numbers are tics (milliseconds since the Epoch). – Jasen Commented Mar 11, 2015 at 1:17 - Hey guys, thanks for the information - @Leo the desired output would be just the TIME of day – ayla Commented Mar 11, 2015 at 1:18
-
1
(new Date(1425909686)).toLocaleTimeString()
– Leo Commented Mar 11, 2015 at 1:20 - 1 @Leo that is super incorrect. – ayla Commented Mar 11, 2015 at 2:43
1 Answer
Reset to default 5If 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./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="d1"></div>
<div id="d2"></div>
本文标签:
版权声明:本文标题:html - How To convert UTC TIMESTAMP only, into local time, on the web with javascript? from http:openweathermap.org - Stack Over 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741943741a2406294.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论