jquery - Will assigning 0 to the 3rd parameter of a JavaScript Date() object always create an end of month date? -


i'm working on jquery credit card expiration date validation script. credit cards expire after last day of expiration month. instance, if card expires on 8/2013 it's through 8/31/2013.

in past on server side i've determined last day of month adding 1 current month, subtracting 1 day.

today noticed when creating new date, if 0 applied 3rd parameter of javascript date() object, resulting date end-of-month day. i've been unable locate online documentation affirm observation.

here sample code.

var month = 10; var year = 2013; var expires = new date(year, month, 0); alert(expires); 

and here jsfiddle example created.

this bit confusing, because thought in javascript months 0 based. i've tested in chrome, firefox, ie, , safari, , behavior appears consistent. returned date consistently displays last day of month. looks lucky find, i'd understand happening here.

am safe run approach assigning end of month date, , if there online documentation can point affirms this? thanks.

months are zero-based. creates end-of-month date in previous month. month 10 november, creating date day 0 in november gives end of october (month 9).

that is, day 0 in november means "the day before 1 november", last day of october. day -1 in november 30 october.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -