Cross-platform Date & Time Picker For React Native

A cross-platform React Native date & time picker component for Android, iOS, and Windows.

Install & Import:

# Yarn
$ yarn add @react-native-community/datetimepicker

# NPM
$ npm i @react-native-community/datetimepicker --save
import React, {useState} from 'react';
import {View, Button, Platform} from 'react-native';
import DateTimePicker from '@react-native-community/datetimepicker';

Basic Usage:

export const App = () => {
  const [date, setDate] = useState(new Date(1598051730000));
  const [mode, setMode] = useState('date');
  const [show, setShow] = useState(false);
  const onChange = (event, selectedDate) => {
    const currentDate = selectedDate || date;
    setShow(Platform.OS === 'ios');
    setDate(currentDate);
  };
  const showMode = (currentMode) => {
    setShow(true);
    setMode(currentMode);
  };
  const showDatepicker = () => {
    showMode('date');
  };
  const showTimepicker = () => {
    showMode('time');
  };
  return (
    <View>
      <View>
        <Button onPress={showDatepicker} title="Show date picker!" />
      </View>
      <View>
        <Button onPress={showTimepicker} title="Show time picker!" />
      </View>
      {show && (
        <DateTimePicker
          testID="dateTimePicker"
          value={date}
          mode={mode}
          is24Hour={true}
          display="default"
          onChange={onChange}
        />
      )}
    </View>
  );
};

Previews:

Cross-platform Date & Time Picker iOS

iOS

Cross-platform Date & Time Picker Android

Android

Cross-platform Date & Time Picker Windows

Windows

Download Details:

Author: react-native-datetimepicker

Live Demo: View The Demo

Download Link: Download The Source Code

Official Website: https://github.com/react-native-datetimepicker/datetimepicker

License: MIT

You Might Be Interested In:

Add Comment