时间戳转换年月日时分秒

//时间转换
timestampToTime (timestamp) {
const dateObj = new Date(+timestamp) // ps, 必须是数字类型,不能是字符串, +运算符把字符串转化为数字,更兼容
const year = dateObj.getFullYear() // 获取年,
const month = dateObj.getMonth() + 1 // 获取月,必须要加1,因为月份是从0开始计算的
const date = dateObj.getDate() // 获取日,记得区分getDay()方法是获取星期几的。
const hours = this.pad(dateObj.getHours()) // 获取时, this.pad函数用来补0
const minutes = this.pad(dateObj.getMinutes()) // 获取分
const seconds = this.pad(dateObj.getSeconds()) // 获取秒
return year + '-' + month + '-' + date + ' ' + hours + ':' + minutes + ':' + seconds

},

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。