鍍金池/ 問答/HTML/ typesctipt 報錯 Property 'format' does not

typesctipt 報錯 Property 'format' does not exist on type 'Date'.

  public getAllDay (begin: any, end: any) {
    const dateAllArr = new Array();
    const ab = begin.split('-');
    const ae = end.split('-');
    const db = new Date();
    db.setUTCFullYear(ab[0], ab[1] - 1, ab[2]);
    const de = new Date();
    de.setUTCFullYear(ae[0], ae[1] - 1, ae[2]);
    const unixDb = db.getTime();
    const unixDe = de.getTime();
    for (let k = unixDb; k <= unixDe;) {
       dateAllArr.push((new Date(parseInt(k))).format().toString());
       k = k + 24 * 60 * 60 * 1000;
    }
    return dateAllArr;
  }

請問怎么解決

回答
編輯回答
純妹

Date類型上不存在format屬性啊。

2018年1月23日 01:31
編輯回答
涼心人

因為 format 這個方法不存在
https://developer.mozilla.org...

2018年7月12日 02:31
編輯回答
墻頭草

這段代碼從各個方面來說錯的不止一點點... 先把需求說明清楚吧?
unixDb unixDe 這兩個值之間單位差 可以用ms計算
K以一天遞增?

format()在push函數(shù)后,即便Date有format方法也調(diào)用有問題??! Date是沒有format()方法的,
可以考慮自己拼接 或者使用toLocaleString()

2017年5月11日 22:49