I am using MomentJS to display a date.
moment(startDate).format('lll')
This will display: Jan 29 2014 03:04
But I would like to remove the year which is "2014" how can I do that?
Here is the link to the momentjs
MomentJS
I am using MomentJS to display a date.
moment(startDate).format('lll')
This will display: Jan 29 2014 03:04
But I would like to remove the year which is "2014" how can I do that?
Here is the link to the momentjs
MomentJS
Share Improve this question edited Feb 7, 2020 at 20:58 Poliakoff 1,6822 gold badges22 silver badges40 bronze badges asked Jan 29, 2014 at 11:52 ObsivusObsivus 8,35913 gold badges56 silver badges98 bronze badges 03 Answers
Reset to default 3I haven't used that library before, but try this:
moment(StartDate, "MMM DD HH:mm");
At least this would work in .NET.
What you want is:
moment(startdate).format('MMM DD h:mm A');
See a javascript example:
http://jsfiddle/remus/rLjQx/
Following worked for me (ES2022 in Angular 17) -
// set locale
moment.locale(locale); // where locale is any valid supported string e.g. 'en', 'es', 'pt', 'fr', etc.
//check that not past year
const now = moment(new Date().toJSON());
const blogDate = moment(v.date); // where v.date is your UTC date input e.g. '2024-02-01T13:36:47.615Z'
const pastYear = now.year() > blogDate.year();
const differenceDays = now.diff(blogDate, 'days');
const date =
differenceDays > 7
? blogDate.format(pastYear ? 'll' : 'MMM DD')
: blogDate.startOf('day').fromNow();
console.log('date', date);
See it live here - https://gaurav.web-developer.in/en/blog