Javascript Date -> numeric vs string -


    var date1 = new date('1900-01-01');     console.log(date1); 

yields: "mon jan 01 1900 01:00:00 gmt+0100 (w. europe standard time)"

    var date2 = new date(1900,1,1);     console.log(date2); 

yields: "thu feb 01 1900 00:00:00 gmt+0100 (w. europe standard time)"

fiddle

but don't understand why!

you can see month difference since when pass individual components (year, month, day, etc) date object constructor, have consider month parameter should start 0:

console.log( new date('1900-01-01').getmonth() );  // 0 

other jan/feb there shouldn't differences in dates.

mdn: https://developer.mozilla.org/en/docs/web/javascript/reference/global_objects/date


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -