react-datepicker vs react-datetime vs react-datetime-picker
日付と時間の選択ライブラリ
react-datepickerreact-datetimereact-datetime-picker類似パッケージ:
日付と時間の選択ライブラリ

これらのライブラリは、Reactアプリケーションにおいて日付や時間を選択するためのインターフェースを提供します。ユーザーが直感的に日付や時間を選択できるようにするためのコンポーネントを提供し、フォームやインターフェースの使いやすさを向上させます。

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
react-datepicker2,932,8228,3533.09 MB436日前MIT
react-datetime262,8662,013291 kB1821年前MIT
react-datetime-picker91,264579227 kB34ヶ月前MIT
機能比較: react-datepicker vs react-datetime vs react-datetime-picker

カスタマイズ性

  • react-datepicker:

    react-datepickerは、日付のフォーマットやスタイルを簡単にカスタマイズできる機能を提供します。CSSを使用して外観を変更したり、特定の日付を無効にすることが可能です。

  • react-datetime:

    react-datetimeは、日付と時間の両方を選択できるカスタマイズ可能なコンポーネントを提供します。特定のフォーマットやスタイルを設定することができ、開発者のニーズに合わせて調整できます。

  • react-datetime-picker:

    react-datetime-pickerは、シンプルで直感的なUIを提供し、ユーザーが簡単に日付と時間を選択できるように設計されています。カスタマイズも可能ですが、主にユーザーエクスペリエンスに重点を置いています。

ユーザーインターフェース

  • react-datepicker:

    react-datepickerは、非常に直感的なUIを持ち、ユーザーがカレンダーから日付を簡単に選択できます。視覚的に魅力的で、ユーザーが操作しやすい設計です。

  • react-datetime:

    react-datetimeは、日付と時間を同時に選択できるインターフェースを提供し、ユーザーが一つのコンポーネントで両方を選択できる利便性があります。

  • react-datetime-picker:

    react-datetime-pickerは、シンプルで一貫性のあるUIを持ち、ユーザーが日付と時間を簡単に選択できるように設計されています。特に、モバイルデバイスでも使いやすいインターフェースを提供します。

ローカライズ

  • react-datepicker:

    react-datepickerは、複数の言語に対応しており、ローカライズの設定が容易です。特定の地域に合わせた日付フォーマットを提供することができます。

  • react-datetime:

    react-datetimeは、ローカライズのオプションがあり、ユーザーの地域に応じた日付と時間の表示が可能です。

  • react-datetime-picker:

    react-datetime-pickerは、ローカライズ機能をサポートしており、異なる地域に合わせた日付と時間の表示が可能です。

拡張性

  • react-datepicker:

    react-datepickerは、プラグインやカスタムコンポーネントを追加することで機能を拡張できます。特定のニーズに応じて、独自の機能を追加することが可能です。

  • react-datetime:

    react-datetimeは、カスタムプロパティを追加することで、特定の機能を拡張することができます。開発者は必要に応じて機能を追加できます。

  • react-datetime-picker:

    react-datetime-pickerは、拡張性があり、必要に応じてカスタムスタイルや機能を追加することができますが、基本的にはシンプルな使用を重視しています。

メンテナンスとサポート

  • react-datepicker:

    react-datepickerは、活発にメンテナンスされており、定期的にアップデートが行われています。コミュニティも活発で、問題解決のためのサポートが得やすいです。

  • react-datetime:

    react-datetimeも定期的にメンテナンスされており、開発者からのフィードバックを受けて改善が行われています。

  • react-datetime-picker:

    react-datetime-pickerは、比較的新しいライブラリですが、活発に開発が進められており、サポートも得やすいです。

選び方: react-datepicker vs react-datetime vs react-datetime-picker
  • react-datepicker:

    シンプルでカスタマイズ可能な日付ピッカーを必要とする場合に選択してください。特に、日付のフォーマットやスタイルを柔軟に設定したい場合に適しています。

  • react-datetime:

    日付と時間の両方を選択する必要がある場合に選択してください。シンプルなAPIを持ち、カスタマイズが容易で、特に両方の選択肢が必要な場合に便利です。

  • react-datetime-picker:

    ユーザーが日付と時間を選択するための統一されたインターフェースを求めている場合に選択してください。特に、シンプルなUIと一貫性のある体験を提供したい場合に適しています。

react-datepicker のREADME

React Date Picker

npm version Test suite codecov Downloads

A simple and reusable Datepicker component for React (Demo)

Installation

The package can be installed via npm:

npm install react-datepicker --save

Or via yarn:

yarn add react-datepicker

You’ll need to install React and PropTypes separately since those dependencies aren’t included in the package. If you need to use a locale other than the default en-US, you'll also need to import that into your project from date-fns (see Localization section below). Below is a simple example of how to use the Datepicker in a React view. You will also need to require the CSS file from this package (or provide your own). The example below shows how to include the CSS from this package if your build system supports requiring CSS files (Webpack is one that does).

import React, { useState } from "react";
import DatePicker from "react-datepicker";

import "react-datepicker/dist/react-datepicker.css";

// CSS Modules, react-datepicker-cssmodules.css
// import 'react-datepicker/dist/react-datepicker-cssmodules.css';

const Example = () => {
  const [startDate, setStartDate] = useState(new Date());
  return <DatePicker selected={startDate} onChange={(date) => setStartDate(date)} />;
};

Configuration

The most basic use of the DatePicker can be described with:

<DatePicker selected={startdate} onChange={(date) => setStartDate(date)} />

You can use onSelect event handler which fires each time some calendar date has been selected

<DatePicker
  selected={date}
  onSelect={handleDateSelect} //when day is clicked
  onChange={handleDateChange} //only when value has changed
/>

onClickOutside handler may be useful to close datepicker in inline mode

See here for a full list of props that may be passed to the component. Examples are given on the main website.

Working with Examples

When using examples from the documentation site, note that they may reference utilities from external libraries. Common imports you might need:

Date manipulation (from date-fns):

import { getYear, getMonth, addDays, subDays, setHours, setMinutes } from "date-fns";

Utility functions:

  • For range() function used in custom headers: import range from "lodash/range";
  • Or implement your own: const range = (start, end, step) => Array.from({ length: (end - start) / step }, (_, i) => start + i * step);

TypeScript types:

import type { ReactDatePickerCustomHeaderProps } from "react-datepicker";

All examples on the documentation site include commented import statements at the top showing exactly what you need to import for your own project.

For a comprehensive guide on imports, see the Common Imports Guide.

Time picker

You can also include a time picker by adding the showTimeSelect prop

<DatePicker selected={date} onChange={handleDateChange} showTimeSelect dateFormat="Pp" />

Times will be displayed at 30-minute intervals by default (default configurable via timeIntervals prop)

More examples of how to use the time picker are given on the main website

Localization

The date picker relies on date-fns internationalization to localize its display components. By default, the date picker will use the locale globally set, which is English. Provided are 3 helper methods to set the locale:

  • registerLocale (string, object): loads an imported locale object from date-fns
  • setDefaultLocale (string): sets a registered locale as the default for all datepicker instances
  • getDefaultLocale: returns a string showing the currently set default locale
import { registerLocale, setDefaultLocale } from  "react-datepicker";
import { es } from 'date-fns/locale/es';
registerLocale('es', es)

<DatePicker
  locale="es"
/>

Locales can be changed in the following way:

  • Globally - setDefaultLocale('es');

Timezone handling

React-datepicker uses native JavaScript Date objects which are timezone-aware. By default, dates are displayed in the user's local timezone. The library does not include built-in timezone conversion utilities.

For detailed information about working with timezones, UTC dates, and common timezone-related scenarios, see the Timezone Handling Guide.

For applications requiring timezone conversion, we recommend using date-fns-tz alongside react-datepicker.

Compatibility

React

We're always trying to stay compatible with the latest version of React. We can't support all older versions of React.

Latest compatible versions:

  • React 16 or newer: React-datepicker v2.9.4 and newer
  • React 15.5: React-datepicker v2.9.3
  • React 15.4.1: needs React-datepicker v0.40.0, newer won't work (due to react-onclickoutside dependencies)
  • React 0.14 or newer: All above React-datepicker v0.13.0
  • React 0.13: React-datepicker v0.13.0
  • pre React 0.13: React-datepicker v0.6.2

Moment.js

Up until version 1.8.0, this package was using Moment.js. Starting v2.0.0, we switched to using date-fns, which uses native Date objects, to reduce the size of the package. If you're switching from 1.8.0 to 2.0.0 or higher, please see the updated example above of check out the examples site for up to date examples.

Browser Support

The date picker is compatible with the latest versions of Chrome, Firefox, and IE10+.

Unfortunately, it is difficult to support legacy browsers while maintaining our ability to develop new features in the future. For IE9 support, it is known that the classlist polyfill is needed, but this may change or break at any point in the future.

Local Development

The main branch contains the latest version of the Datepicker component.

To begin local development:

  1. Run yarn install from project root
  2. Run yarn build from project root
  3. Run yarn start from project root

The last step starts documentation app as a simple webserver on http://localhost:5173.

You can run yarn test to execute the test suite and linters. To help you develop the component we’ve set up some tests that cover the basic functionality (can be found in /tests). Even though we’re big fans of testing, this only covers a small piece of the component. We highly recommend you add tests when you’re adding new functionality.

Please refer to CONTRIBUTING.md file for more details about getting set up.

The examples

The examples are hosted within the docs folder and are ran in the simple app that loads the Datepicker. To extend the examples with a new example, you can simply duplicate one of the existing examples and change the unique properties of your example.

Accessibility

Keyboard support

  • Left: Move to the previous day.
  • Right: Move to the next day.
  • Up: Move to the previous week.
  • Down: Move to the next week.
  • PgUp: Move to the previous month.
  • Shift+PgUp: Move to the same day and month of the previous year. If that day does not exist, moves focus to the last day of the month.
  • PgDn: Move to the next month.
  • Shift+PgDn: Move to the same day and month of the next year. If that day does not exist, moves focus to the last day of the month.
  • Home: Move to the first day (e.g Sunday) of the current week.
  • End: Move to the last day (e.g. Saturday) of the current week.
  • Enter/Esc/Tab: close the calendar. (Enter & Esc calls preventDefault)

For month picker

  • Left: Move to the previous month.
  • Right: Move to the next month.
  • Enter: Select date and close the calendar

License

Copyright (c) 2014-2025 HackerOne Inc. and individual contributors. Licensed under MIT license, see LICENSE for the full license.