1、时间戳 ==》年-月-日 时:分:秒
function full_data_transfer(millisecond){
if(millisecond==null|| millisecond==undefined ||millisecond==''){
throw new error("没有定义输入参数");
}else{
if(!(typeof millisecond =='number')){
throw new error("输入参数不是数值格式!!");
}
}
try {
var date =new Date(millisecond);
} catch (e) {
throw new error("无法转化为日期格式!!");
}
var year = date.getFullYear();
var month =date.getMonth()+1;//月
month =month<10? '0'+month:month;
var day =date.getDate();//日
day =day<10?'0'+day:day;
var hour = date.getHours(); //时
hour = hour<10?'0'+hour:hour;
var min = date.getMinutes();//分
min = min<10?'0'+min:min;
var sec = date.getSeconds(); // 秒
sec = sec<10?'0'+sec:sec;
return year+'-'+month+'-'+day+' '+hour+':'+min+':'+sec ;
}
function timeToTransfer(time) {
var str = '';
if(time) {
var transfer = new Date(time);
var year = transfer.getFullYear(),
month = transfer.getMonth() + 1,
dates = transfer.getDate(),
hours = transfer.getHours(),
minutes = transfer.getMinutes();
if(month < 10) {
month = '0' + month;
};
if(dates < 10) {
dates = '0' + dates;
};
if(hours < 10) {
hours = '0' + hours;
};
if(minutes < 10) {
minutes = '0' + minutes;
};
str = year + '-' + month + '-' + dates + ' ' + hours + ':' + minutes;
}
return str;
}
3、时间戳转换成《月-日 时:分》格式
function timelineTransfer(time) {
var str = '';
if(time) {
var transfer = new Date(time);
var month = transfer.getMonth() + 1,
dates = transfer.getDate(),
hours = transfer.getHours(),
minutes = transfer.getMinutes();
if(month < 10) {
month = '0' + month;
};
if(dates < 10) {
dates = '0' + dates;
};
if(hours < 10) {
hours = '0' + hours;
};
if(minutes < 10) {
minutes = '0' + minutes;
};
str = month + '-' + dates + ' ' + hours + ':' + minutes;
}
return str;
}
4、时间==》《年-月-日 时:分:秒 》转换成 《年-月-日》
function timeTransferNoMinite(time) {
var str = '';
if(time) {
var firstNum = time.indexOf(' ');
str = time.substring(0, firstNum);
}
return str;
}
5、时间==》将《年-月-日 时:分 》转换成 《月-日 时:分》
function timeTransfer(time) {
var str = '';
if(time) {
var firstNum = time.indexOf('-');
str = time.substring(firstNum + 1);
}
return str;
}