Format dates coming from Restful Service in Javascript

This question already has an answer here:

  • How do I format a Microsoft JSON date? 37 answers

  • 不知道如何解析日期,我无法在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

    上一篇: 为什么JSON.stringify()接受Date对象?

    下一篇: 在Javascript中使用来自Restful Service的日期格式