js时间戳转化时间格式

// 判断是否前面补0
add0 (m) {
return m < 10 ? '0' + m : m
},
// 时间转化
timeFormat (timestamp) {
// timestamp是整数,否则要parseInt转换,不会出现少个0的情况
var time = new Date(timestamp)
// var year = time.getFullYear()
// var month = time.getMonth() + 1
// var date = time.getDate()
var hours = time.getHours()
var minutes = time.getMinutes()
var seconds = time.getSeconds()
// return year + '-' + this.add0(month) + '-' + this.add0(date) + ' ' + this.add0(hours) + ':' + this.add0(minutes) + ':' + this.add0(seconds)
return this.add0(hours) + ':' + this.add0(minutes) + ':' + this.add0(seconds)
},
// 时间戳转化为时间
formatDateTime:function (timeStamp) {
if(timeStamp != null&&timeStamp != 0){
var date = new Date();
date.setTime(timeStamp * 1000);
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
var d = date.getDate();
d = d < 10 ? ('0' + d) : d;
var h = date.getHours();
h = h < 10 ? ('0' + h) : h;
var minute = date.getMinutes();
var second = date.getSeconds();
minute = minute < 10 ? ('0' + minute) : minute;
second = second < 10 ? ('0' + second) : second;
// return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
return y + '-' + m + '-' + d;
}else{
return ''
}
}

 

这只是为了方便,纯属记录!

// 时间戳转化为时间
formatDateTime:function (timeStamp) {
if(timeStamp != null&&timeStamp != ){
var date = new Date();
date.setTime(timeStamp * );
var y = date.getFullYear();
var m = date.getMonth() + ;
m = m < ? ('0' + m) : m;
var d = date.getDate();
d = d < ? ('0' + d) : d;
var h = date.getHours();
h = h < ? ('0' + h) : h;
var minute = date.getMinutes();
var second = date.getSeconds();
minute = minute < ? ('0' + minute) : minute;
second = second < ? ('0' + second) : second;
// return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
return y + '-' + m + '-' + d;
}else{
return ''
}
}
上一篇:Atitit.提升稳定性-----分析内存泄漏PermGen OOM跟解决之道...java


下一篇:Intel 82599网卡异常挂死原因