寻找将日期格式更改为秒的JavaScript方法。
2017年7月16日00:05 am
完整格式下方(我只需要月份日期,年份时间:上午分钟。请让我知道删除不需要的内容)
var date = new Date();
显示“Sun Jul 16 2017 00:05:50 GMT+0800 (SGT)
”
由于
答案 0 :(得分:0)
试试这个:
console.log(getFormattedDate(new Date()));
function getFormattedDate(date) {
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
var year = date.getFullYear();
var day = date.getDate().toString();
day = day.length > 1 ? day : '0' + day;
var hour = date.getHours().toString();
var minutes = date.getMinutes().toString();
var ampm = hour >= 12 ? 'PM' : 'AM';
return monthNames[date.getMonth()] + ' ' + day + ', ' + year + ' ' + hour + ':' + minutes + ' ' + ampm;
}