1

I want to generate this date format using Moment.js:

Mon Apr 1 17:51:40 2019

Right now, I am getting this format instead:

Mon Apr 01 2019 17:51:40 GMT+0530 (IST)
MarredCheese
  • 17,541
  • 8
  • 92
  • 91
Ekta Sahu
  • 59
  • 1
  • 5
  • 2
    Look at the documentation for Date object - it's all there – Jaromanda X Apr 02 '19 at 05:10
  • your problem looks same like this. https://stackoverflow.com/questions/15993913/format-date-with-moment-js. I hope this will help you.. – Asmi Apr 02 '19 at 05:15
  • I down voted this post because the OP did not have any attempt or code to solve the problem. And probably did not check the documentation of the mentioned library, which would actually have the answer right in the landing page: https://momentjs.com/ – Tyro Hunter Apr 02 '19 at 05:33
  • @ektasahu , can you tell me how is that answer is correct and you should note the time that how have given the answer first and then you mark the answer as correct – Narendra Chouhan Apr 02 '19 at 06:21

4 Answers4

1

use this:

Moment(new Date(this.state.date)).format('MMMM Do YYYY, h:mm:ss a')

or whatever format you want. you can check them on here: https://momentjs.com/

displayname
  • 1,044
  • 7
  • 12
1

Try this:

 var dateTime = new Date("Mon Apr 01 2019 17:51:40 GMT+0530 (IST)");
 dateTime = moment(dateTime).format("ddd MMM D HH:mm:ss YYYY");
Coder
  • 389
  • 5
  • 15
0

It's already a valid date string - just make a new Date:

console.log(new Date("Mon Apr 01 2019 17:51:40 GMT+0530 (IST)"));
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
0

first you need to install moment

 let formatedDate = moment('Mon Apr 01 2019 17:51:40 GMT+0530 (IST)').format('ddd MMM DD HH:mm:ss YYYY');
 console.log(formatedDate)

output: Mon Apr 01 17:51:40 2019

Done You can check it

Narendra Chouhan
  • 2,291
  • 1
  • 15
  • 24