Javascript date function showing wrong date

后端 未结 3 1291
抹茶落季
抹茶落季 2021-01-29 13:34

The code below shows the day, month and year as:

6
3
116

Which is obviously wrong dates.

var date= new Date();
var day=date.get         


        
3条回答
  •  花落未央
    2021-01-29 14:14

    You're querying the wrong functions and misunderstanding the output.

    getDay() returns the day of the week.

    getMonth() returns the month, but January starts with 0.

    getYear() returns the year minus 1900

    You are probably looking for:

    getDate(), getMonth()+1, getFullYear()

提交回复
热议问题