Describe the bug
The date picker still shows local date when timeZone prop is set to UTC.
From this documentation:
supports a timeZone prop that allows you to display and handle dates in a specific timezone
To Reproduce
Steps to reproduce the behavior:
import { useState } from 'react'
import DatePicker from 'react-datepicker'
function App() {
const [inputUtc, setInputUtc] = useState('2026-01-01T00:00:00.000Z')
const [pickerValue, setPickerValue] = useState<Date | null>(new Date('2026-01-01T00:00:00.000Z'))
const [outputUtc, setOutputUtc] = useState('2026-01-01T00:00:00.000Z')
return (
<>
<input
aria-label="input-utc"
value={inputUtc}
onChange={(event) => {
const date = new Date(event.target.value)
setInputUtc(event.target.value)
setPickerValue(date)
setOutputUtc(date.toISOString())
}}
/>
<DatePicker
selected={pickerValue}
onChange={(date: Date | null) => {
setPickerValue(date)
setInputUtc(date!.toISOString())
setOutputUtc(date!.toISOString())
}}
timeZone="UTC"
/>
<input aria-label="output-utc" value={outputUtc} readOnly />
</>
)
}
export default App
Expected behavior
Expect the date in the date picker to be the UTC date which is 2026-01-01.
Screenshots
Desktop (please complete the following information):
- OS: Windows 11
- Browser: Chrome
Describe the bug
The date picker still shows local date when
timeZoneprop is set toUTC.From this documentation:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Expect the date in the date picker to be the UTC date which is
2026-01-01.Screenshots
Desktop (please complete the following information):