Get Current Date With Month And Year in React Native Android iOS

The JavaScript’s inbuilt function Date().getDate() gives us the facility to retrieve Get Current Date With Month And Year in both android and iOS applications on button click. So in this tutorial we would going to get current date using Date().getDate() function, retrieve current month using Date().getMonth() function and current year using  Date().getFullYear() function and display inside react native app using Alert dialog.

Contents in this project Get Current Date With Month And Year in React Native App:

1. Import StyleSheet, View, Alert and Button component in your project.

2. Create a function named as ShowCurrentDate(). Now we would get current date, month and year using Date() function and store each value into separate Var variable. Finally we would show all values on application screen with – (Dash) into Alert dialog.

NoteWe need to +1 to month to show the correct month because by default in react native January starts from 0(Zero).

3. Create a Parent View in render’s return block and add a Button component inside it. Now we would set onPress event on button and call the ShowCurrentDate() function on button onPress.

4. Create Style for View.

5. Complete source code for App.js File :

 

Screenshot in Android device :


Get Current DateScreenshot in iOS Application :