json /DATA(XXXXX)/转化为日期格式

function data_string(str) {
var d = eval('new ' + str.substr(1, str.length - 2));
console.log(d.getMilliseconds());
var ar_date = [d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds()];
var atime = '';
for(var i = 0; i < ar_date.length; i++) {
if(i == 0) {
if(ar_date[i] == 0) {
atime += ar_date[i] + "0";
} else {
atime += ar_date[i];
}

} else if(i == 3) {
if(ar_date[i] == 0) {
atime += " " + ar_date[i] + "0";
} else {
atime += " " + ar_date[i];
}
} else if(i < 3) {
if(ar_date[i] == 0) {
atime += "-" + ar_date[i] + "0";
} else {
atime += "-" + ar_date[i];
}
} else if(i > 3) {
if(ar_date[i] == 0) {
atime += ":" + ar_date[i] + "0";
} else {
atime += ":" + ar_date[i];
}
}
// else if(i==ar_date.length){
// if(ar_date[i] == 0) {
// atime += ":" + ar_date[i] + "00";
// } else {
// atime += ":" + ar_date[i];
// }
// }
//ar_date[i] = dFormat(ar_date[i]);
}
console.log(atime);
return atime;

function dFormat(i) {
return i < 10 ? "0" + i.toString() : i;
}
}

 

返回“2019-1-9 9:32”

获取时间函,转:https://blog.csdn.net/mning199201/article/details/81390868

posted @ 2020-01-09 09:33  绯颜旧雨  阅读(344)  评论(0编辑  收藏  举报