簡體   English   中英

Moment JS在1月(第0個月)不工作

[英]Moment js is not working for january (month 0)

我知道當月的索引為0。 基本上,我將此this.month設置為0到11之間的任何整數,然后運行以下代碼。 由於某些原因,它不想更新一月月份的矩量(其值為0)。 有什么問題,我該如何解決?

 const d: Moment = moment(); if (this.month) d.month(this.month); console.log("Month value: " + this.month); console.log("Moment value: " + d.month()); 

Console.log為this.month = 2(三月)返回以下內容

月值:2矩值:2

Console.log為this.month = 1(二月)返回以下內容

月值:1矩值:1

Console.log為此返回以下內容。month = 0(一月)

月值:0 矩值:1

if (this.month)

如果this.month是一個偽造的值(例如0),則以下指令將不會運行。

作為HMR建議,您可能需要使用===運營商(或者其否定!== )來檢查this.month不是null也不undefined

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM