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 –
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.
Hi, I am a professional Ionic and React Native Pixel Perfect App Designer and Developer, with expertise in Client Communication, Bug Fixing, Third Party Lib, Version Control Tools, Requirement Understanding, and managing teams, I have 6+ years of experience in the same domain as well as in Codeigniter, JS, IoT, and more than 10 other languages. For the last 6+ years, not a single day went without design/development.
Please follow me on Medium: https://nehadwivedi1004.medium.com/
@Krunal Durne thank you so much, you encourage me to write more.
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!