JavaScript does currently not have a built-in standard object that represents a date without a time. When you use the Date object, despite its name you should think of it as a "date and time" object, closer to what other languages call DateTime. There is always an implied time component, even you don't provide one.
The constructor of the Date object has several different forms that vary by the arguments you pass in. If you pass a string, it will try to parse that string. However, the effects can vary depending on what that string contains, and can vary across implementations.
For example:
// This will be parsed as UTC at midnight (but doesn't work in IE8)
new Date("2013-05-31")
// This will be parsed as local time in Chrome, and cause "Invalid Date" in IE
new Date("2013-05-31 00:00:00")
// This will be parsed as local time at midnight, and usually works in all browsers, but is not standardized.
new Date("2013/05/31")
That last one might be acceptable, but it still seems fishy to me. Most people don't use that format, they are more likely to enter mm/dd/yyyy or dd/mm/yyyy, which can lead to ambiguity depending on culture and the date you enter.
You are probably better off passing numeric arguments to the Date constructor:
new Date(2013, 4, 31)
Note that when you do this, the months run 0-11 instead of 1-12. Because I passed a 4, this represents the month of May. This is a common source of error, so watch it carefully.
I should also mention that you can eliminate all of the browser variations and support any format you want, if you use a library such as Moment.js. For example:
// This will be parsed as local time
moment('2013-05-31','YYYY-MM-DD')
// This will be parsed as UTC
moment.utc('2013-05-31','YYYY-MM-DD')
There are many other good date/time libraries as well. If you need to support older browsers, then Moment is a good choice. But if you're supporting mostly modern browsers, then try Luxon or date-fns instead.
new Date('2013/12/12 00:00:00')instead. - raina77ow