Sometimes, we want to get the current date in React Native.
In this article, we’ll look at how to get the current date in React Native.
How to get the current date in React Native?
To get the current date in React Native, we can use the Date
constructor.
For instance, we write:
import * as React from 'react';
import { View, Text } from 'react-native';
import Constants from 'expo-constants';
import { Card } from 'react-native-paper';
export default function App() {
return (
<View>
<Text>{new Date().toLocaleString()}</Text>
</View>
);
}
to create a new Date
instance and call toLocaleString
on it to return a localized date string and render it in the Text
component.
Conclusion
To get the current date in React Native, we can use the Date
constructor.