Alan Varghese Aniyan Alan Varghese Aniyan - 3 months ago 19
Javascript Question

How to customize year format in a date format using moment.js?

I need to get the following format using moment.js

Thu, 10 Oct 16, 2:00PM

The closest format I found using moment.js is using the following function.


where dataVar is the required date object.The output looks as follows

Thu, Oct 16, 2016 12:00 AM

I could not find any way to customise this date format or get the required result.


According to the moment docs you should be able to get your result by passing the following formatting string:

moment(dateVar).format('ddd, DD MMM YY, H:mmA');

I think this string should get you the desired result. If I run it with the current date it returns this:

moment(new Date()).format('ddd, DD MMM YY, H:mmA');
//"Wed, 02 Nov 16, 10:25AM"

And extensive list of your display options with formatting strings is here: