How to use Moment Js in react native

Introducation:

Here we discuss about “How to use Moment Js in react native“, if you want to perform any date related action then there is a well-known library but if you want to use it in your project then there is a npm plugin.

I’m a big fan of React Native, because it is very easy to implement complicated concepts and designs, in below example i am going to explain you in detail how to use moment in a very simple way.

Example Output –

https://www.itechinsiders.com/ - react native moment js

so let’s get started to use react-moment, you follow these steps.

Step1: 

First we need to install the react-moment plugin.

npm install –save moment react-moment

Step2: 

One more thing if you want to use TimeZone related functionality then must install this plugin.

npm install –save moment-timezone

Step3: 

Now we are ready to use the plugin, so we import this in which page you want to use this.

import Moment from 'react-moment';
 
import 'moment-timezone';

Step4:  Now we see how to use this.

<Moment style={{color:'#000'}} fromNow element={Text}>{date}</Moment>

It shows the date in – formate of 24 hours just like 1 hour ago,1 day ago etc

Note: It’s important to set element type if want to show it as text.

So the topic is “How to use Moment Js in react native“ completed, you can find the next lesson here.

You can find my post on medium as well click here please follow me on medium as well.

If have any query/issue, please feel free to ask.

Happy Coding Guys.

Related Post

3 Replies to “How to use Moment Js in react native”

  1. Hey Neha!

    First Off, Thank you and congratulation on that wonderful post smashing article! This is awesome…

    I appreciate that you took a simple by explaining the process step by step and how to use Moment Js with React Native.

    What I Most like It extends native JavaScript date capabilities with a variety of features, such as relative time, calendar time, durations and multi-language support and It also has a decent list of plugins that allow for additional features like local time-zone support, recurrence, and even Twitter integration.

    I’ve been React Developer for a year and I found out this was great stuff for me, This is an incredibly instructive post that I’ve bookmarked. I intend to go step by step to develop this skill.

    keep doing, you did well!

Leave a Reply

Your email address will not be published. Required fields are marked *