ios中'-'不兼容,需要使用'/'代替
export const formatYMDWithLine = function(date) {
if (!date) {
return ''
}
if (typeof date === 'string') {
date = date.replace(/\-/g, '/').replace('T', ' ')
}
const d = new Date(date)
const Y = d.getFullYear()
const M = d.getMonth() + 1
const D = d.getDate()
return Y + '-' + M.toString().padStart(2, '0') + '-' + D.toString().padStart(2, '0')
}
export const formatYMDHMSWithLine = function(date) {
if (!date) {
return ''
}
if (typeof date === 'string') {
date = date.replace(/\-/g, '/').replace('T', ' ')
}
const d = new Date(date)
const Y = d.getFullYear()
const M = d.getMonth() + 1
const D = d.getDate()
const H = d.getHours()
const MM = d.getMinutes()
const S = d.getSeconds()
return Y + '-' + M.toString().padStart(2, '0') + '-' + D.toString().padStart(2, '0') + ' ' + H.toString().padStart(2, '0') + ':' + MM.toString().padStart(2, '0') + ':' + S.toString().padStart(2, '0')
}