How to get the Current Date in ReactNative?

The JavaScript runtime in React Native has access to date information just like any other environment. As such, simply:

new Date()

... will give you the current date. Here's the MDN on working with dates in JS.

If you want a good JS library to make working with dates even easier, check out MomentJS.


I think this should work;

new Date().toLocaleString()

It will return date and time formatted in your local format (usually in the below format);

"6/22/2021, 2:59:00 PM"

I used {new Date()} was generating Invariant Violation: Objects are not valid error the following date function worked for me.

const getCurrentDate=()=>{
 
      var date = new Date().getDate();
      var month = new Date().getMonth() + 1;
      var year = new Date().getFullYear();
 
      //Alert.alert(date + '-' + month + '-' + year);
      // You can turn it in to your desired format
      return date + '-' + month + '-' + year;//format: d-m-y;
}

For more info https://reactnativecode.com/get-current-date-react-native-android-ios-example It works for ios as well.