Ekra
Ekra

Reputation: 3301

Moment.js to format dateString

Need to use Moment.js to format the below Date string.

Wed Sept 01 2017 04:33:01 GMT+0400 (+04)

I tried to use below but it didn't work

moment(e.dateVale, 'D MMMM D YYYY, hh:mm:ss a')

I referred http://momentjs.com/ but couldn't make it work.

Any help would be highly appreciated

Upvotes: 0

Views: 196

Answers (2)

Georgian-Sorin Maxim
Georgian-Sorin Maxim

Reputation: 224

You need to use new Date for creating a Date object from the String you're passing and then will enable you to use moment for formatting that Date object.

See this:

console.log(moment(new Date('Wed Sept 03 2017 06:33:01 GMT+0400 (+04)')).format( 'D MMMM D YYYY, hh:mm:ss a'));

Upvotes: 1

Kritesh Semwal
Kritesh Semwal

Reputation: 163

Try This:

console.log(moment('Wed Sep 06 2017 04:33:01 GMT+0400 (+04)', 'ddd MMM DD YYYY HH:mm:ss [GMT]Z').utc())

Day and date combination in the string provided by you is not correct and will give following error.

moment.invalid(/* Wed Sept 01 2017 04:33:01 GMT+0400 (+04) */)

Upvotes: 1

Related Questions