Javascript date function showing wrong date

后端 未结 3 1250
抹茶落季
抹茶落季 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:11

    getDay() returns the day of the week from 0-6 for Sun-Sat,

    getMonth() returns the month from 0-11, so 3 means April,

    getYear() has been deprecated and replaced with getFullYear() which should be used instead.

    It just looks like all of these functions do something different than what you were expecting.

    To get day of the month from 1-31: getDate(),

    To get month like you were expecting, just add 1: getMonth() + 1

提交回复
热议问题