我有以下代码
new Date(1501796503599)
返回值
Fri Aug 04 2017 03:11:43 GMT+0530 (IST)
我需要将上述值显示为"Today, 3:11 am"
。有没有办法做到这一点
答案 0 :(得分:2)
var time = moment(1501796503599).calendar();
console.log(time);

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script>
&#13;
答案 1 :(得分:1)
答案 2 :(得分:0)
你可以简单地使用javascript检查,没有任何依赖。
var yourDate = new Date(1501796503599);
var today = new Date();
var isToday = (today.toDateString() == yourDate.toDateString());
if(isToday){
yourDate = "Today, " + yourDate.toLocaleTimeString();
}
else{
yourDate;
}
答案 3 :(得分:0)
var monthName = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
$(function(){
var newDate = '';
newDate = new Date(1501796503599)
if (newDate != '')
var str = newDate.getDate() + "-" + monthName[newDate.getMonth()] + "-" + newDate.getFullYear()+
" " + newDate.getHours() + ":" + newDate.getMinutes() + ":" + newDate.getSeconds();
console.log(str);
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;
尝试这个。