moment.js日期比较 - 今天前一天还是今天后两天? [英] moment.js date comparison - day before today or two days after today?
本文介绍了moment.js日期比较 - 今天前一天还是今天后两天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力争取片刻.js查询以确定日期(例如:2014年10月12日)是否在今天前一天或今天后两天。
I'm struggling with a moment.js "query" to figure out if a date (ex : 12/10/2014) is within the range of the day before "today", or two days after "today".
谷歌搜索并查看moment.js文档,但没有找到任何关于如何做到这一点的正确或可理解的例子......
Been googling around, and checking the moment.js documentation, but haven't found any proper or understandable examples on how to do this...
推荐答案
使用片刻,您可以执行以下操作...
Using moment, you can do the following...
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
<script>
var now = moment(),
begin = moment().subtract(1, 'days').startOf('day'),
end = moment().add(2, 'days').endOf('day')
document.write(now.isAfter(begin) && now.isBefore(end))
</script>
这篇关于moment.js日期比较 - 今天前一天还是今天后两天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文