I want to format Date YYYYY-MM-DD, but getFullYear does not exist.

Asked 1 years ago, Updated 1 years ago, 25 views

I would like the date to be in YYYY-MM-DD format.
It is said that getFullYear does not exist.

error messages:

Uncaught TypeError:date.getFullYear is not a function
    at formatDate
happens

source code:

function formatDate(date){

        varmonth=("0"+(date.getMonth()+1)).slice(-2);
        vardate=("0" + date.getDate()) .slice(-2);

        varformatted=`${date.getFullYear()}-${month}-${date}`.replace(/\n|\r/g, ');
        return formatted;
    }

javascript

2022-09-30 19:34

1 Answers

vardate=("0"+date.getDate()) .slice(-2);

This is because you have overwritten the date.


2022-09-30 19:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.