日期格式化

master
taoshihan 2 years ago
parent 30d672ac18
commit a890decfdc

@ -427,7 +427,8 @@ var app=new Vue({
if(data.result!=null){
let r=data.result;
_this.visitor=r;
// _this.visitor.created_at=r.created_at;
_this.visitor.created_at=formatDate(r.created_at);
_this.visitor.updated_at=formatDate(r.updated_at);
// _this.visitor.refer=r.refer;
// _this.visitor.city=r.city;
// _this.visitor.client_ip=r.client_ip;

@ -187,4 +187,25 @@ function alertSound(id,src){
var p = b.play();
p && p.then(function(){}).catch(function(e){});
}
//日期格式化
function formatDate(dateString, format = 'yyyy-MM-dd HH:mm:ss') {
const date = new Date(dateString);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hour = String(date.getHours()).padStart(2, '0');
const minute = String(date.getMinutes()).padStart(2, '0');
const second = String(date.getSeconds()).padStart(2, '0');
const formattedDate = format
.replace(/yyyy/g, year)
.replace(/MM/g, month)
.replace(/dd/g, day)
.replace(/HH/g, hour)
.replace(/mm/g, minute)
.replace(/ss/g, second);
return formattedDate;
}
;

Loading…
Cancel
Save