To convert a string in the following formates:
•MM-dd-yyyy
•yyyy/MM/dd
•MM/dd/yyyy
•MMMM dd, yyyy
•MMM dd, yyyy
like:
Variable with Date Format as MM-dd-yyyy:
var dateString = "03-20-2008"; // MM-dd-yyyy
Variable with Date Format as yyyy/MM/dd:
var dateString = "2008/03/20"; // yyyy/MM/dd
Variable with Date Format as MM/dd/yyyy:
var dateString = "03/20/2008"; // MM/dd/yyyy
Variable with Date Format as MMMM dd, yyyy:
var dateString = "March 20, 2008"; // MMMM dd, yyyy
Variable with Date Format as MMM dd, yyyy:
var dateString = "Mar 20, 2008"; // MMM dd, yyyy
You can use any of the above date string formats that can be passed to the javascript Date Object:
var myDate = new Date(dateString);
document.write("Date :" + myDate.getDate());
document.write("<br>");
document.write("Month : " + myDate.getMonth());
document.write("<br>");
document.write("Year : " + myDate.getFullYear());