Typesctipt reported an error 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;
  }

could you tell me how to solve the problem

Mar.21,2021

because the format method does not exist
https://developer.mozilla.org.


the format attribute does not exist on the Date type.


this code is more than a little wrong in every way. Why don't you make the requirements clear first?
unixDb unixDe the unit difference between these two values can be calculated with ms
K to increase by one day?

format () after the push function, it is a problem to call the format method even if Date has it! Date does not have a format () method.
can consider splicing or using toLocaleString ()

.
Menu