如何将unix时间戳转换为日历日期moment.js [英] How to convert unix timestamp to calendar date moment.js
本文介绍了如何将unix时间戳转换为日历日期moment.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Unix时间戳,我正在尝试将其转换为日历日期,例如MM/DD/YYYY
.
到目前为止,我有这个:
I have a unix timestamp, and I'm trying to convert it into a calendar date such as MM/DD/YYYY
.
So far, I have this:
$(document).ready(function() {
var value = $("#unixtime").val(); //this retrieves the unix timestamp
var dateString = moment(value).calendar();
alert(dateString);
});
当我尝试打印日历日期时,窗口会显示无效日期".谁能帮我吗?
When I try to print out the calendar date, the window says "Invalid date". Can anyone help me out?
推荐答案
Using moment.js as you asked, there is a unix
method that accepts unix timestamps in seconds:
var dateString = moment.unix(value).format("MM/DD/YYYY");
这篇关于如何将unix时间戳转换为日历日期moment.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文