【问题标题】:Format date with moment [closed]用时刻格式化日期[关闭]
【发布时间】:2021-09-28 09:19:26
【问题描述】:

除了 JS 之外的所有语言都提出了类似的问题。 根据变天,我需要知道是今天变天,还是明天或其他天?

【问题讨论】:

    标签: javascript angular typescript date angular9


    【解决方案1】:

    你不需要 momentJS 来完成这个简单的任务 您需要向计算函数提供所需的日期。

     let calculate = (date: Date) => {
        let now = new Date();
        if (date.getMonth() == now.getMonth() && date.getFullYear() == now.getFullYear()) {
            if (date.getDate() == now.getDate()) {
                return "Yey, Today"
            }
            if (date.getDate() == now.getDate() + 1) {
                return "Yey, tomorrow"
    
            }
            return "Other Date"
        }
        return "Other Date"
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多