Skip to content

timeZone prop does not display date in selected timezone #6255

@ribbles

Description

@ribbles

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

Image

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Chrome

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions