关于时间选择器 示例: ?
?const endTime = [Wed May 04 2022 00:00:00 GMT+0800 (中国标准时间), Sat May 21 2022 00:00:00 GMT+0800 (中国标准时间), __ob__: Observer]
??const?[startTime,endTime]?=?formatDate(endTime)
console.log(startTime,endTime)
2022-05-04T00:00:00
2022-05-21T23:59:59
方法如下:
export function formatDate(dateRange: string[]): string[] {
if (Array.isArray(dateRange) && dateRange.length === 2) {
let [start, end] = dateRange
const startDate = new Date(start)
const endDate = new Date(end)
startDate.setDate(startDate.getDate() + 1)
endDate.setDate(endDate.getDate() + 1)
start = startDate.toISOString().replace(/T.+/, 'T00:00:00')
end = endDate.toISOString().replace(/T.+/, 'T23:59:59')
return [start, end]
}
return []
}
|