最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Moment isBetween with inclusion parameter do not work - Stack Overflow

programmeradmin3浏览0评论

I am using momentjs.

I want to show a value if a date is between two date (and include those 2 dates)

following moment Documentation

moment('2019/09/02').isBetween(
  '1900/01/01',
  '2019/09/02',
  '[]'
)

Why is this returning false ? it should return true as today is included in today.

I am using momentjs.

I want to show a value if a date is between two date (and include those 2 dates)

following moment Documentation

moment('2019/09/02').isBetween(
  '1900/01/01',
  '2019/09/02',
  '[]'
)

Why is this returning false ? it should return true as today is included in today.

Share Improve this question edited Sep 2, 2019 at 9:12 Eddie 26.8k6 gold badges38 silver badges59 bronze badges asked Sep 2, 2019 at 9:11 CrocsxCrocsx 7,62015 gold badges86 silver badges176 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 16

Check again the doc.

The third param is the granularity and the fourth param is the interval.

so in your case, it should be

moment('2019/09/02').isBetween(
  '1900/01/01',
  '2019/09/02',
  null, // can be year, month .... the granularity of your aprison
  '[]'
)

Use this trick.

moment('2019/09/02).isBetween('1900/01/01', '2019/09/02 23:59:59');
发布评论

评论列表(0)

  1. 暂无评论