If you replace the dash with a slash, it will be parsed, then you can use the date functions to get different components (or convert to a string using one of the different toString () functions).
var date = new Date( Date.parse( old.replace(/-/g,'/') ) );
alert( date.getMonth() + '/' + date.getDate() + '/' + date.getFullYear() );
This has the advantage that you can use the date as a date for calculations, rather than just formatting the strings. If string formatting is all you need. And , date strings are always valid, then using the @Guffa substr method is probably the best way to handle this.
source
share