GitHub

🚧🚧 Looking for collaborators and financial backers 🚧🚧

Please support maintenance of the module with a monthly donation or help us with issues and pull requests.

Become a backer on OpenCollective or sponsor us on GitHub Sponsors.

See this issue for context. Thank you!


This repository was moved out of the react native community GH organization, in accordance to this proposal. The module is still published on npm under the old namespace (as documented) but will be published under a new namespace at some point, with a major version bump.

npm downloads Supports Android and iOS MIT License

React Native date & time picker component for iOS, Android and Windows (please note Windows is not actively maintained).

Screenshots

Expand for screenshots
iOS

Android

Windows

Table of contents

Requirements

The module supports the new React Native architecture (Fabric rendering of iOS components, and turbomodules on Android).

Expo users notice

This module is part of Expo Go - see docs. However, Expo Go may not contain the latest version of the module and therefore, the newest features and bugfixes may not be available. If you use Expo Go, use the command npx expo install @react-native-community/datetimepicker (not yarn or npm) to install this module - Expo will automatically install the latest version compatible with your Expo SDK (which may not be the latest version of the module available).

If you're using a Dev Client, rebuild the Dev Client after installing the dependencies.

If you're using the expo prebuild command and building your native app projects (e.g. with EAS Build or locally), you can use the latest version of the module.

Getting started

npm install @react-native-community/datetimepicker --save

or

yarn add @react-native-community/datetimepicker

Autolinking is not yet implemented on Windows, so manual installation is needed.

On iOS, run npx pod-install after installing. Then rebuild your project.

Usage

import DateTimePicker from '@react-native-community/datetimepicker';
Expand for examples

We give two equivalent examples on how to use the package on all supported platforms.

Recommended imperative api usage on Android

While the component-approach as given in the second paragraph works on Android, the recommended approach is to use the imperative api given in the first paragraph.

Read more about the motivation in Android imperative API.

"export const App = () => { const [date, setDate] = useState(new Date(1598051730000)); const showMode = (currentMode) => { DateTimePickerAndroid.open({ value: date, onValueChange: (event, selectedDate) => setDate(selectedDate), mode: currentMode, is24Hour: true, }); }; const showDatepicker = () => { showMode('date'); }; const showTimepicker = () => { showMode('time'); }; return (

Read the original on github.com ↗