moment.calendar()没有时间 [英] moment.calendar() without the time

查看:508
本文介绍了moment.calendar()没有时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在没有时间的情况下使用moment.calendar()选项...所以不要使用
上周二下午5点,我想要上周二。
现在有人知道时刻是否有解决方案吗?
我发现这个小提琴 http://jsfiddle.net/nawxZ/ ,显然显示了一个解决方案为此,但我看不出它应该如何工作?
谢谢
carl

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));


推荐答案

从2.10.5开始,您可以:

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'
})

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

这篇关于moment.calendar()没有时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆