/**
- 時間格式化
- 將 2020-09-23T11:54:16.000+0000 格式化成 2020-09-23
- @param datetime 日期格式
*/
export function format (datetime) {
return formatWithSeperator(datetime, '-', ':')
}
第一種:yy-mm-dd
/**
- 時間格式化
- 將 2019-01-01T12:00:00.000+0000 格式化成類似 2019-01-01
- datetime:需要格式化的時間
- dateSeprator:時間分隔符
- @param datetime 國際化日期格式
/
export function formatWithSeperator (datetime, dateSeprator, timeSeprator) {
if (datetime != null) {
const dateMat = new Date(datetime)
const year = dateMat.getFullYear()
const month = dateMat.getMonth() + 1
const day = dateMat.getDate()
const timeFormat = year + dateSeprator + month + dateSeprator + day
return timeFormat
}
}
第二種:yy-mm-dd hh:mm:ss
/* - 時間格式化
- 將 2019-01-01T12:00:00.000+0000 格式化成類似 2019-01-01 12:00:00
- 可以指定日期和時間分隔符
- @param datetime 國際化日期格式
*/
export function formatWithSeperator (datetime, dateSeprator, timeSeprator) {
if (datetime != null) {
const dateMat = new Date(datetime)
const year = dateMat.getFullYear()
const month = dateMat.getMonth() + 1
const day = dateMat.getDate()
const hh = dateMat.getHours()
const mm = dateMat.getMinutes()
const ss = dateMat.getSeconds()
const timeFormat = year + dateSeprator + month + dateSeprator + day + ' ' + hh + timeSeprator + mm + timeSeprator + ss
return timeFormat
}
}