Testing Date Creation From Various String Formats

This code tests the creation of a DATE object from common American string date formats. Results vary by browser.

by kboucher

JavaScript

var i,
    dates = [
    "2-Jan-2012",
    "2 Jan 2012",
    "January 2, 2012",
    "1/2/2012",
    "2/1/2012",
    "1-2-2012",
    "2-1-2012",
    "01/02/2012",
    "02/01/2012",
    "2 JAN 2012",
];

for ( i = 0; i < dates.length; i++ ) {

    document.write( new Date( dates[ i ] ).toLocaleDateString()  + "<br />" );
    
}