1.获取当前系统时间时分秒
// 标准时间格式转化为年月日时分秒
export function ssDateTimeFn(timestamp) {if (!timestamp) {return timestamp}// timestamp是整数,否则要parseInt转换,不会出现少个0的情况const time = new Date(timestamp)const year = time.getFullYear()const month = time.getMonth() + 1const date = time.getDate()const hours = time.getHours()const minutes = time.getMinutes()const seconds = time.getSeconds()return year + '-' + add0(month) + '-' + add0(date) + ' ' + add0(hours) + ':' + add0(minutes) + ':' + add0(seconds)
}
import {ssDateTimeFn
} from '@/utils/commonss' // 公共事件引入使用
ssDateTimeFn(new Date())
2.// 标准时间格式转化为年月日时分
// 标准时间格式转化为年月日时分
function mmDateTimeFn(timestamp) {if (!timestamp) {return timestamp}// timestamp是整数,否则要parseInt转换,不会出现少个0的情况const time = new Date(timestamp)const year = time.getFullYear()const month = time.getMonth() + 1const date = time.getDate()const hours = time.getHours()const minutes = time.getMinutes()// const seconds = time.getSeconds()return year + '-' + add0(month) + '-' + add0(date) + ' ' + add0(hours) + ':' + add0(minutes)
}
3.年月日不带时分
// 年月日 不带时分
function dateFormat(timestamp) {if (!timestamp) {return timestamp}// timestamp是整数,否则要parseInt转换,不会出现少个0的情况const time = new Date(timestamp)const year = time.getFullYear()const month = time.getMonth() + 1const date = time.getDate()return year + '-' + add0(month) + '-' + add0(date)
}