在Javascript中使用来自Restful Service的日期格式

这个问题在这里已经有了答案:

  • 如何格式化Microsoft JSON日期? 37个答案

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

    上一篇: Format dates coming from Restful Service in Javascript

    下一篇: javascript date from controller