I recommend you to use a library like this:
https://github.com/phstc/jquery-dateFormat.
But if you want to format a string from 2014-08-24
into 24 Aug 2014
, you can wirte something like this:
function myFormatDate(d){
var mothes = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var d_y = d.split('-')[0];
var d_m = d.split('-')[1];
var d_d = d.split('-')[2];
var mon = mothes[parseInt(d_m,10)-1];
var dd = parseInt(d_d,10);
if(d_y == "0000"){ // EDITED
return dd + " " + mon;
}else{
return dd + " " + mon + " " + d_y;
}
}
var d = "2014-08-24";
alert(myFormatDate(d));
Hope this helps.