import React from 'react'; import type { TimeRangePickerProps } from 'antd'; import { DatePicker, Space } from 'antd'; import dayjs from 'dayjs'; import type { Dayjs } from 'dayjs'; const { RangePicker } = DatePicker; const onChange = (date: Dayjs) => { if (date) { console.log('Date: ', date); } else { console.log('Clear'); } }; const onRangeChange = (dates: null | (Dayjs | null)[], dateStrings: string[]) => { if (dates) { console.log('From: ', dates[0], ', to: ', dates[1]); console.log('From: ', dateStrings[0], ', to: ', dateStrings[1]); } else { console.log('Clear'); } }; const rangePresets: TimeRangePickerProps['presets'] = [ { label: 'Last 7 Days', value: [dayjs().add(-7, 'd'), dayjs()] }, { label: 'Last 14 Days', value: [dayjs().add(-14, 'd'), dayjs()] }, { label: 'Last 30 Days', value: [dayjs().add(-30, 'd'), dayjs()] }, { label: 'Last 90 Days', value: [dayjs().add(-90, 'd'), dayjs()] }, ]; const App: React.FC = () => ( Now ~ EOD, value: () => [dayjs(), dayjs().endOf('day')], // 5.8.0+ support function }, ...rangePresets, ]} showTime format="YYYY/MM/DD HH:mm:ss" onChange={onRangeChange} /> ); export default App;