1.web 时间日期格式转换
function getDateNumber(num, type) {
num=num.replace("-","/");
//兼容IE,不支持‘.’之后的时间戳,判断去掉
if(num.indexOf(".")>-1){
num=num.substring(0,num.indexOf("."))
}
if (null == type) {
type = 1;
}
var date = new Date(num);
var year = date.getFullYear();
var month = date.getMonth() + 1;// js从0开始取
var date = date.getDate();
if (month < 10) {
month = "0" + month;
}
if (date < 10) {
date = "0" + date;
}
if (type == 0) {
return month + "-" + date;
} else if (type == 1) {
return year + "-" + month + "-" + date;
}
}
例如: getDateNumber(o.publishAt, 0)
转载于:https://blog.51cto.com/82711020/1973668