How to Get Time Using Moment JS in React Native?

Jan 23, 2023 . Admin

This article will provide example of using moment js in react native. this example will help you how to get time using moment js in react native. We will look at example of how to get time using moment js. In this article, we will implement a react native get current date time. So, let's follow few step to create example of get time using moment js in react native.

In this example, We will get to time using moment js in react can use fromNow method in react native.below's this example.

Step 1: Download Project

In the first step run the following command to create a project.

expo init ExampleApp
Step 2: 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={}>{moment("20111031", "YYYYMMDD").fromNow() }</Text>

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',

  text: {
    fontSize: 24,

  date: {
    fontSize: 24,
    fontWeight: 'bold',
    padding: 15

Step 3: 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.


It will help you...

#React Native