根据Date对象时间戳 - 获取时分秒
time = new Date().getTime();
transTimeFormatHour: function(time) {
var transTime = Math.floor((time / 60 / 60));
return transTime = transTime.toString().length == 1 ? "0" + transTime : transTime;
},
transTimeFormatMinute: function(time) {
var transTime = Math.floor((time / 60) % 60);
return transTime = transTime.toString().length == 1 ? "0" + transTime : transTime;
},
transTimeFormatSeconds: function(time) {
var transTime = Math.floor(time % 60);
return transTime = transTime.toString().length == 1 ? "0" + transTime : transTime;
},
根据具体日期时间 - 获取年日月时分秒
time = "2022-12-12";
replaceTime: function(time) {
return time.replace(/-/g, "/");
},
getFullYear: function(time) {
return transTime = new Date(this.replaceTime(time)).getFullYear();
},
getMonth : function(time) {
return transTime = new Date(this.replaceTime(time)).getMonth()+1;
},
getDate: function(time) {
return transTime = new Date(this.replaceTime(time)).getDate();
},
getHours: function(time) {
var transTime = new Date(this.replaceTime(time)).getHours();
return transTime = transTime.toString().length == 1 ? "0" + transTime : transTime;
},
getMinutes: function(time) {
var transTime = new Date(this.replaceTime(time)).getMinutes();
return transTime = transTime.toString().length == 1 ? "0" + transTime : transTime;
},
getSeconds: function(time) {
var transTime = new Date(this.replaceTime(time)).getSeconds();
return transTime = transTime.toString().length == 1 ? "0" + transTime : transTime;
},