Format dates coming from Restful Service in Javascript
This question already has an answer here:
不知道如何解析日期,我无法在2016年附近找到它,但可以像这样格式化它
const date = '/Date(-62135568000000)/'
const zeroify = num => num < 10 ? '0' + num : num
const monthify = month => {
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', '...']
return months[month]
}
function parseDate(dateStr) {
const date = new Date(parseInt(dateStr.match(/(d+)/)[1]) / 100)
const parts = [
monthify(date.getMonth()), ' ',
zeroify(date.getDate()), ', ',
date.getFullYear()
]
return '(' + parts.join('') + ')'
}
console.log(
parseDate(date)
)
链接地址: http://www.djcxy.com/p/8170.html