Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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));
question from:https://stackoverflow.com/questions/32420447/moment-calendar-without-the-time

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
186 views
Welcome To Ask or Share your Answers For Others

1 Answer

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...