I am using the below code to convert a string to a date.
I pass this “2010-06-23 00:00:00.0” as the input to the function. Instead of returning 21-June-2010 as the date, it returns me 21-Jul-2010. What could be the problem?
function getDateFromString(string){
var month = string.substring(5,7);
var day = string.substring(8,10);
var year = string.substring(0,4);
var dateValue = new Date(year,month,day);
dateFormat(dateValue, "yyyy-mm-dd");
return date;
}
The months are numbered from zero, not one. In other words, “6” is July, not June.
(I mean, they’re numbered that way as far as the JavaScript “Date” class is concerned.)