ProAnswers.org

How to Create Date object from year month value?

We can pass in numbers to Date class constructors.

the year,

the zero-based month (January is 0, February is 1, and so on)

the day of the month (1 through 31),

the hours (0 through 23),

minutes,

seconds,

milliseconds

The year and month are required.

 







    

        var aDate = new Date(2012, 4, 5, 17, 55, 55); 

        document.writeln(aDate);

        //Sat May 05 2012 17:55:55 GMT-0700 (Pacific Daylight Time)

       

    









 

If the day of the month isn't supplied, it's assumed to be 1. all other omitted arguments are assumed to be 0.

 



    var aDate = new Date(2012, 0); 

    document.writeln(aDate);

    //Sun Jan 01 2012 00:00:00 GMT-0800 (Pacific Standard Time)