title: how to change date format in react
body: <p>I am new to React and i have been working on this project which requires me to use datepicker.</p>
  <p>I am using DateTimePickerModal module in my react native project
  and the output of the date i am getting is like this == Fri May 21 2021 13:45:52 GMT+0530 (IST) ==</p>
  <p>that ouput datatype is an object.</p>
  <p>my required output should be like this == 21/05/2021 1:45 pm ==</p>
  <p>can any one please guide me here ?</p>
  <pre><code>import React, { useState, useEffect } from 'react'
  import { View, StyleSheet, Text, TouchableOpacity } from 'react-native';
  import DateTimePickerModal from 'react-native-modal-datetime-picker';
  import AsyncStorage from '@react-native-async-storage/async-storage';
  
  const Rem = function (props) {
      //const [dateswitch ,setDateSwitch]=useState(true)
      const [isDatePickerVisible, setDatePickerVisibility] = useState(false);
      //button state
      const [b1, setBl] = useState(false);
      const [b2, setB2] = useState(false);
      //date state
      const [b1date, setb1Date] = useState('');
      const [b2date, setb2Date] = useState('');
  
      //============== showDatePicker ==================
  
      //get item from storage
      const gettime = async () =&gt; {
          try {
              const value1 = await AsyncStorage.getItem('b1');
              if (value1 !== null) {
                  // value previously stored
                  setb1Date(value1);
              }
              const value2 = await AsyncStorage.getItem('b2');
              if (value2 !== null) {
                  // value previously stored
                  setb2Date(value2);
              }
          } catch (e) {
              // error reading value
          }
      };
      gettime();
      const b1showDatePicker = () =&gt; {
          setBl(true);
          setDatePickerVisibility(true);
      };
      const b2showDatePicker = () =&gt; {
          setB2(true);
          setDatePickerVisibility(true);
      };
  
      const hideDatePicker = () =&gt; {
          setDatePickerVisibility(false);
      };
  
      const handleConfirm = async (date) =&gt; {
          const d = date.toString()
          if (b1 === true) {
              try {
                  //console.warn('A date has been picked: ', d);
                  await AsyncStorage.setItem('b1', d);
                  setb1Date(d);
                  setBl(false);
                  hideDatePicker();
              } catch (err) {
                  console.log(err);
              }
          } else {
              try {
                  //console.warn('A date has been picked: ', d);
                  await AsyncStorage.setItem('b2', d);
                  setb2Date(d);
                  setB2(false);
                  hideDatePicker();
              } catch (err) {
                  console.log(err);
              }
          }
      };
  
  
  
      return (
          &lt;View &gt;
              &lt;View style={styles.button_container}&gt;
                  &lt;TouchableOpacity onPress={b1showDatePicker}&gt;
                      &lt;Text style={styles.button}&gt;reminder 1 &lt;/Text&gt;
                  &lt;/TouchableOpacity&gt;
                  &lt;TouchableOpacity onPress={b2showDatePicker}&gt;
                      &lt;Text style={styles.button}&gt;reminder 2&lt;/Text&gt;
                  &lt;/TouchableOpacity&gt;
              &lt;/View&gt;
              &lt;Text style={styles.text}&gt;{b1date}&lt;/Text&gt;
              &lt;Text style={styles.text}&gt;{b2date}&lt;/Text&gt;
              &lt;DateTimePickerModal
                  is24Hour={true}
                  isVisible={isDatePickerVisible}
                  mode=&quot;datetime&quot;
                  onConfirm={handleConfirm}
                  onCancel={hideDatePicker}
              /&gt;
          &lt;/View&gt;
      );
  
  }
  
  export default Rem;
  
  
  </code></pre>