There are generally 4 types of JavaScript date input formats:
Type | Example |
---|---|
ISO Date | "2015-03-25" (The International Standard) |
Short Date | "03/25/2015" |
Long Date | "Mar 25 2015" or "25 Mar 2015" |
Full Date | "Wednesday March 25 2015" |
//ISO 8601 syntax (YYYY-MM-DD) console.log(new Date("2015-03-25")); //ISO Dates (Year and Month) //ISO dates can be written without specifying the day (YYYY-MM): console.log(new Date("2015-03")); //ISO Dates (Only Year) console.log(new Date("2015")); //ISO Dates (Date-Time) //ISO dates can be written with added hours, minutes, and seconds (YYYY-MM-DDTHH:MM:SSZ): //Separate date and time with a capital T. //Indicate UTC time with a capital Z. console.log(new Date("2015-03-25T12:00:00Z")); //to modify the time relative to UTC, remove the Z and add +HH:MM or -HH:MM instead: //Modify the time relative to UTC by adding +HH:MM or subtraction -HH:MM to the time. console.log(new Date("2015-03-25T12:00:00-06:00")); //JavaScript Short Dates. //Short dates are written with an "MM/DD/YYYY" syntax like this: console.log(new Date("03/25/2015")); //JavaScript Long Dates. //Long dates are most often written with a "MMM DD YYYY" syntax like this: console.log(new Date("Mar 25 2015")); //Month and day can be in any order: console.log(new Date("25 Mar 2015")); //And, month can be written in full (January), or abbreviated (Jan): console.log(new Date("January 25 2015")); console.log(new Date("Jan 25 2015")); //Commas are ignored. Names are case insensitive: console.log(new Date("JANUARY, 25, 2015")); //JavaScript Full Date //JavaScript will accept date strings in "full JavaScript format": console.log(new Date("Wed Mar 25 2015 09:56:24 GMT+0100 (W. Europe Standard Time)")); //JavaScript will ignore errors both in the day name and in the time parentheses: console.log(new Date("Fri Mar 25 2015 09:56:24 GMT+0100 (Tokyo Time)"));