第一种方法:
/** * 格式化时间为:yyyy-MM-dd HH:mm:ss * @param date * @returns {string} */
jsDateFormatter: function (date) {
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes()+ seperator2 + date.getSeconds();
return currentdate;
},
第二种方法:
GMTToStr(time){
let date = Date(time);
var fullYear = date.getFullYear();
var month = date.getMonth() + 1;
var _date = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
if(month < 10){month = '0'+month}
if(_date < 10){_date = '0'+_date}
if(hours < 10){hours = '0'+hours}
if(minutes < 10){minutes = '0'+minutes}
if(seconds < 10){seconds = '0'+seconds}
Str=fullYear + '-' + month + '-' + _date + ' ' + hours + ':' + minutes + ':' + seconds
return Str
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)