我需要将日期格式更改为dd-mm-YYYY HH:mm:ss。目前我正在获得YYY-mm-dd HH:mm:ss。有人可以帮我这个吗?
for (var course in data) {
if (data[course]['days'] == value) {
id[i] = data[course]['id'];
name[i] = data[course]['name'] + " " + data[course]['startDate']['date'];
i++;
}
}
答案 0 :(得分:2)
date = date.split('-'); //split and break into array
date = date[2] + '-' + date[1] + '-' + date[0]; //change the order you need
<小时/> OP后更新更新了问题
date_parts = date.split(' '); //split and break into array get HH:mm:ss
date = date_parts[0].split('-');
date = date[2] + '-' + date[1] + '-' + date[0] + ' ' + date_parts[1]; //change the order you need
答案 1 :(得分:0)
试试这个:
function formatDate (input) {
var datePart = input.match(/\d+/g),
year = datePart[0].substring(2), // get only two digits
month = datePart[1], day = datePart[2];
return day+'/'+month+'/'+year;
}
alert(formatDate ('2010/01/18')); // "18/01/10"
<强> Demo 强>