vuepress-theme-reco/util/formatDate.js
2019-10-21 17:56:03 +08:00

24 lines
649 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 时间格式化的方法
* 创建时间2019-10-08
* 作者:刘晓北
* 邮箱: 15732451723@163.com
*/
// 将时间格式化成 YYYY/MM/DD HH:mm:SS
export function fromatDateTime (time, type) {
time = time.replace(/-/g, '/')
const date = new Date(time)
const Y = date.getFullYear()
const M = date.getMonth() + 1
const D = date.getDate()
let H = date.getHours()
H = H > 9 ? H : '0' + H
let m = date.getMinutes()
m = m > 9 ? m : '0' + m
let S = date.getSeconds()
S = S > 9 ? S : '0' + S
const dt = type === 'date' ? Y + '/' + M + '/' + D : Y + '/' + M + '/' + D + ' ' + H + ':' + m + ':' + S
return dt
}