//时间格式化
function timeUtil(dat){
if('' == dat || !dat) return '';
var _date = getDate(dat);
var year = _date.getFullYear();
var month = _date.getMonth() + 1;
var day = _date.getDate();
var hour = _date.getHours();
var minute = _date.getMinutes();
var second = _date.getSeconds();
//将小于9的字符串前缀补零
function formatNumber(n){
n = n.toString();
return n[1] ? n : '0' + n;
}
//将时间对象转换 YYYY/MM/DD hh:mm:ss
function timeYMDHMS(){
return [year,month,day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':');
}
//将时间对象转换YYYY-MM-DD hh:mm:ss
function timeYMDHMS1(){
return [year,month,day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':');
}
//将时间对象转换MM-DD hh:mm
function timeMDhs(){
return [month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':');
}
//将时间对象转换YYYY.MM.DD
function timeYMD(){
return [year, month, day].map(formatNumber).join('.');
}
//将时间对象转换YYYY-MM-DD
function timeYMD1(){
return [year, month, day].map(formatNumber).join('-');
}
//将时间对象转换YYYY/MM/DD
function timeYMD2(){
return [year, month, day].map(formatNumber).join('/');
}
//将时间对象转换 hh:mm:ss
function timeHMS(){
return [hour, minute, second].map(formatNumber).join(':');
}
return {
timeYMDHMS:timeYMDHMS,
timeYMDHMS1:timeYMDHMS1,
timeMDhs:timeMDhs,
timeYMD:timeYMD,
timeYMD1:timeYMD1,
timeYMD2:timeYMD2,
timeHMS:timeHMS
}
}
var DateFr = {
timeYMDHMS: function (time) {
return timeUtil(time).timeYMDHMS();
},
timeYMDHMS1: function(time){
return timeUtil(time).timeYMDHMS1();
},
timeMDhs: function(time){
return timeUtil(time).timeMDhs();
},
timeYMD: function(time){
return timeUtil(time).timeYMD();
},
timeYMD1: function(time){
return timeUtil(time).timeYMD1();
},
timeYMD2: function(time){
return timeUtil(time).timeYMD2();
},
timeHMS:function(time){
return timeUtil(time).timeHMS();
}
}
module.exports = {
timeYMDHMS: DateFr.timeYMDHMS,
timeYMDHMS1: DateFr.timeYMDHMS1,
timeMDhs: DateFr.timeMDhs,
timeYMD: DateFr.timeYMD,
timeYMD1: DateFr.timeYMD1,
timeYMD2: DateFr.timeYMD2,
timeHMS: DateFr.timeHMS
}