how can i convert the following string to the required format in javascript:
2013-12-01 03:22:03 = 01 Dec '13
Thanks
how can i convert the following string to the required format in javascript:
2013-12-01 03:22:03 = 01 Dec '13
Thanks
Off the top of my head
function conv(str) {
var d=new Date(str.replace(/-/g,"/"));
var day = d.getDate();
if (day<10) day ="0"+day;
var yyyy=""+d.getFullYear();
return ""+day +" "+["Jan","Feb",..."Dec"][d.getMonth()]+" '"+yyyy.substring(2);
}
var dStr = conv("2013-12-01 03:22:03");
The reason to convert from - to / is that not all browsers accept the format with -
new Date('2013-12-01 03:22:03');
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date