Moment.js - 明天,今天和昨天 [英] Moment.js - tomorrow, today and yesterday

查看:1242
本文介绍了Moment.js - 明天,今天和昨天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要时刻()。fromNow()功能,但是当日期结束时它太精确了 - ex。我不希望它在'3小时'但'今天'显示 - 所以基本上是'每日'精度。

I'd like the moment().fromNow() functionality, but when the date is close it is too precise - ex. I don't want it to show 'in 3 hours' but 'today' - so basically with a 'daily' precision.

我尝试使用时刻()。calendar()函数,如果日期不同则不会格式化是超过1天

I tried using the moment().calendar() function, it doesn't format if the date difference is more than 1 day

推荐答案

您也可以这样做以获取今天和明天以及昨天的日期

You can also do this to get the date for today and tomorrow and yesterday

let today     = moment(new Date());

let tomorrow  = moment(new Date()).add(1,'days');

let yesterday = moment(new Date()).add(-1, 'days');

这篇关于Moment.js - 明天,今天和昨天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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