Remove time from GMT time format

前端 未结 8 2506
有刺的猬
有刺的猬 2021-02-18 23:01

I am getting a date that comes in GMT format, Fri, 18 Oct 2013 11:38:23 GMT. The problem is that the time is messing up the timeline that I am using.

How can I strip ou

相关标签:
8条回答
  • 2021-02-18 23:44

    You could use Moment.js, a library that provides many helper functions to validate, manipulate, display and format dates and times in JavaScript.

    Using Moment.js lib:

    var dateString = new Date('Mon Jan 12 00:00:00 GMT 2015');
    moment(dateString).format('YYYY-MM-DD HH:mm');
    

    Or simplified:

    moment('Mon Jan 12 00:00:00 GMT 2015').format('YYYY-MM-DD HH:mm')
    
    0 讨论(0)
  • 2021-02-18 23:49

    I'm using this workaround :

    // d being your current date with wrong times
    new Date(d.getFullYear(), d.getMonth(), d.getDate())
    
    0 讨论(0)
提交回复
热议问题