时间转化
mark等于 -:为 "YYYY-MM-DD HH:MM:";
all: 为true显示年月日时分秒 "YYYY-MM-DD HH:MM:SS" , 为false显示年月日 "YYYY-MM-DD";
days: 为true返回 【时间,星期】;
调用实列:1:Date.prototype.form('-',true,true) 》》 【YYYY-MM-DD HH:MM:SS ,星期】;
JS:
Date.prototype.form = function form(mark='/',all=1,days=0) {
var date = new Date()+'';
var dateData = {
year:date.split(' ')[3],
month:date.split(' ')[2],
day:date.split(' ')[1],
time:date.split(' ')[4],
hour:date.split(' ')[4].split(':')[0],
minute:date.split(' ')[4].split(':')[1],
second:date.split(' ')[4].split(':')[2],
};
var month = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; //月份
month.map(function (val,ins) {
if(val == date.split(' ')[1]){
dateData['month']=ins+1
}
});
var day = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']; //星期
day.map(function (val,ins) {
if(val == date.split(' ')[0]){
dateData.day=ins+1;
}
});
var re_date = `${date.split(' ')[3]}${mark}${dateData.month}${mark}${date.split(' ')[2]}`;//年月日
var re_time = date.split(' ')[4]; //时分秒;
if(days){
if(all){
return [re_date+' '+re_time,dateData.day];
}
else {
return [re_date,dateData.day];
}
}
if(all){
return re_date+' '+re_time;
}
return re_date;
}
当前时间往后推迟 (ps:以天数为基数)
mark:'以上mark的等于同等';
days:为true返回 【时间,星期】,
Date.prototype.addTime(day,mark,days);
调用实列:
1:Date.prototype.addTime(10,'/',true)
JS:
Date.prototype.form = function form(mark='/',all=1,days=0) {
var date = new Date()+'';
var dateData = {
year:date.split(' ')[3],
month:date.split(' ')[2],
day:date.split(' ')[1],
time:date.split(' ')[4],
hour:date.split(' ')[4].split(':')[0],
minute:date.split(' ')[4].split(':')[1],
second:date.split(' ')[4].split(':')[2],
};
var month = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; //月份
month.map(function (val,ins) {
if(val == date.split(' ')[1]){
dateData['month']=ins+1
}
});
var day = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']; //星期
day.map(function (val,ins) {
if(val == date.split(' ')[0]){
dateData.day=ins+1;
}
});
var re_date = `${date.split(' ')[3]}${mark}${dateData.month}${mark}${date.split(' ')[2]}`;//年月日
var re_time = date.split(' ')[4]; //时分秒;
//需要星期
if(days){
if(all){
return [re_date+' '+re_time,dateData.day];
}
else {
return [re_date,dateData.day];
}
}
if(all){
return re_date+' '+re_time;
}
return re_date;
}
Date.prototype.addTime = function addTime(day=0,mark='/',days=0) {
var nowDate = new Date().valueOf();
var noeDayTime = 10e2*60*60*24*day;
var addTime = nowDate+noeDayTime;
var date =new Date(addTime)+'';
console.log(date);
var dateData = {
year:date.split(' ')[3],
month:date.split(' ')[2],
day:date.split(' ')[1],
time:date.split(' ')[4],
hour:date.split(' ')[4].split(':')[0],
minute:date.split(' ')[4].split(':')[1],
second:date.split(' ')[4].split(':')[2],
};
var month = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; //月份
month.map(function (val,ins) {
if(val == date.split(' ')[1]){
dateData['month']=ins+1
}
});
var day = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']; //星期
day.map(function (val,ins) {
if(val == date.split(' ')[0]){
dateData.day=ins+1;
}
});
var re_date = `${date.split(' ')[3]}${mark}${dateData.month}${mark}${date.split(' ')[2]}`;//年月日
var re_time = date.split(' ')[4]; //时分秒;
//需要星期
if(days){
return [re_date+' '+re_time,dateData.day];
}
return re_date+' '+re_time;
}