您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

将Unix时间戳转换为JavaScript中的时间

将Unix时间戳转换为JavaScript中的时间

let unix_timestamp = 1549312452

// Create a new JavaScript Date object based on the timestamp

// multiplied by 1000 so that the argument is in milliseconds, not seconds.

var date = new Date(unix_timestamp * 1000);

// Hours part from the timestamp

var hours = date.getHours();

// Minutes part from the timestamp

var minutes = "0" + date.getMinutes();

// Seconds part from the timestamp

var seconds = "0" + date.getSeconds();



// Will display time in 10:30:23 format

var formattedTime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);



console.log(formattedTime);

有关Date对象的更多信息,请参考MDN或ECMAScript5规范。

javascript 2022/1/1 18:15:09 有490人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶