How to Use Moment js in React Native?
Sep 07, 2022 . Admin
This article will provide example of Using Moment JS in React Native. step by step explain How to use MomentJS library with React Native. I explained simply step by step react native moment Code Example. it's simple example of React Native Get Current Date.
In this example,We will use moment js in react native.you can install moment js library in you project.you can easy and simply use moment js in react native.
Step 1: Download ProjectIn the first step run the following command to create a project.
expo init ExampleAppStep 2: Install library
Install moment.js by running the following command in your project:
npm install moment --saveStep 3: App.js
In this step, You will open the App.js file and put the code.
import React,{useState} from 'react'; import { StyleSheet, Text, View} from 'react-native'; import moment from 'moment' export default function App() { return ( <View style={styles.container}> <Text style={styles.text}>Date Using moment.js</Text> <Text style={styles.date}>{moment().format('YYYY-MM-DD')}</Text> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', }, text: { fontSize: 24, }, date: { fontSize: 24, fontWeight: 'bold', padding: 15 } });Step 4: Run Project
In the last step run your project using the below command.
expo start
You can QR code scan in Expo Go Application on mobile.
Output:
It will help you...