简体   繁体   中英

Convert epoch time to readable format in javascript

My epoch time is in milliseconds. I am using a javascript function below but i am getting wrong results. Hope someone would help me out.

 function() {
var dt = new Date(1427441622783);
var hour = dt.getHours();}

or I am using this

function(){
var dt = new Date(1427441622783*1000);
var hour = dt.getHours();}

expected result is 13 hours but i am getting in first case 7 hour and second case 18 hours

your code is getting desired result 13 please check once

var dt = new Date(1427441622783);
var hour = dt.getHours();
alert(hour);
alert(dt);

Check jsfiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM