【问题标题】:Angular: Exclude time in Date comparisonAngular:在日期比较中排除时间
【发布时间】:2020-12-01 01:53:52
【问题描述】:

这里this.startDate.valueSun Aug 30 2020 05:30:00 GMT+0530 (India Standard Time)this.endDate.valueSun Aug 30 2020 00:00:00 GMT+0530 (India Standard Time)。由于时间不同,因此在这种情况下进行比较。

if (moment(this.startDate.value).isAfter(moment(this.endDate.value,'day'))) {
    //
} 

有什么办法可以通过上面的比较来排除时间。

【问题讨论】:

    标签: angular angular-moment


    【解决方案1】:

    可以这样查看:

    moment('2010-10-20').isAfter('2009-12-31', 'day'); // true
    

    您也可以使用年或月作为粒度单位 parma!

    这是一个fiddle 来测试它。

    【讨论】:

    • 检查上面的小提琴!
    【解决方案2】:

    在以下代码中工作:

    if (moment(this.startDate.value.format('YYYY-MM-DD')).isAfter(moment(this.endDate.value).format('YYYY-MM-DD'))) {
        //..
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 1970-01-01
      • 2015-07-20
      相关资源
      最近更新 更多