how can i convert the following string to the required format in javascript:
2013-12-01 03:22:03 = 01 Dec '13
Thanks
new Date('2013-12-01 03:22:03');
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
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 -
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.