时间戳转化为Date
//1.Timestamp转换Date格式(2019-01-01 12:00:00)
function transform ( data) {
var time;
if ( data) {
var time = new Date ( data) ;
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 ( ) ;
time = year+ '-' + addZero ( month) + '-' + addZero ( date) + ' ' + addZero ( hours) + ':' + addZero ( minutes) + ':' + addZero ( seconds) ;
}
return time;
}
function addZero ( m) {
return m< 10 ? '0' + m: m;
}
//2.Timestamp转换Date格式(2019-01-01)
function newTime ( data) {
var newTime;
if ( data) {
var time = new Date ( data) ;
var year = time. getFullYear ( ) ;
var month = time. getMonth ( ) + 1 ;
var date = time. getDate ( ) ;
newTime = year+ '-' + addZero ( month) + '-' + addZero ( date) ;
}
return newTime;
}