js converts Chinese standard time to the time in the specified format


//Display value from field in MySQL database in time format: 2017-08-08 17:27:47
//Get the data object, and then display the value of the data object: 'Oct 10, 2017 9:26:16 AM'
即 data[i].createtime='Oct 10, 2017 9:26:16 AM';
//First convert the Chinese standard time format string to date type
var createtime=new Date(data[i].createtime);

Just call the function:
formatDate(createtime);
The final display is: 2017-08-08 17:27:47





function formatTen(num) {
return num > 9 ? (num + "") : ("0" + num);
}

function formatDate(date) {
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
return year + "-" + formatTen(month) + "-" + formatTen(day)+" "+hour+":"+minute+":"+second;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326401553&siteId=291194637