Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

moment.calendar() without the time

I would like to use the moment.calendar() option without the time... so instead of "Last Tuesday at 5pm" I want "Last Tuesday". Does anybody know whether moment has a solution for that by now? I found this fiddle http://jsfiddle.net/nawxZ/, which apparently shows a solution for that, but I can't see how this is supposed to work? thanks carl

function log(str) {     $('body').append('<p>' + str + '</p>'); }  log(moment().calendar()); log(moment().calendar(true)); 
like image 767
carl Avatar asked Sep 06 '15 05:09

carl


People also ask

How do I remove time from moment date?

We can remove the time portion from a date with the startOf method. We pass in a date with the hour and minutes set into the moment function. Then we call startOf with the 'day' argument to get return a moment object with the time set to midnight of the same date.

How do you use moments in calendar?

moment(). calendar({ sameDay: '[Today]', nextDay: '[Tomorrow]', nextWeek: 'dddd', lastDay: '[Yesterday]', lastWeek: '[Last] dddd', sameElse: 'DD/MM/YYYY' }); moment(). calendar({ sameDay: function (now) { if (this. isBefore(now)) { return '[Will Happen Today]'; } else { return '[Happened Today]'; } /* ...

How can I get current date in moment?

To get current date with Moment and JavaScript, we use the moment function without any arguments. const datetime = moment(); to call moment to get a moment object with the current date.

Is MomentJS deprecated?

Moment construction falls back to js Date. This is discouraged and will be removed in an upcoming major release. This deprecation warning is thrown when no known format is found for a date passed into the string constructor.


1 Answers

starting from moment 2.10.5 you can do:

moment(/*your date*/).calendar(null,{     lastDay : '[Yesterday]',     sameDay : '[Today]',     nextDay : '[Tomorrow]',     lastWeek : '[last] dddd',     nextWeek : 'dddd',     sameElse : 'L' }) 

see: http://momentjs.com/docs/#/displaying/calendar-time/

like image 179
Fareed Alnamrouti Avatar answered Sep 30 '22 02:09

Fareed Alnamrouti