Example of React Native Moment NPM Yarn Package

Hello friends, In today’s tutorial we would learn about React Native Moment NPM package. Many of us heard about this package before or maybe you are hearing about this package now. But this is a very important package and comes with many date format regarding facilities. Now the main purpose of this package is to managing data and time formats in multiple ways, converting data and time to many formats even in the yesterday and tomorrow format. So in this tutorial we would learn about Example of React Native Moment NPM Yarn Package.

Contents in this project Example of React Native Moment NPM Yarn Package :-

1. First of all we have to install React Native Moment package in our react native project. So open your project’s main Root directory in Command Prompt or Terminal and execute below command.

OR

Screenshot :-

2. Now we have to install moment-timezone package with moment package. It is used to control Time zone related functions. So again Open your react native project Root directory in CMD or Terminal and execute below command.

OR

Screenshot :-

3. Now it’s time to start coding for the App. Open your project’s main App.js file and put below code inside it.

Explanation :- In below source code, We’re using Moment package to convert date into multiple formats.

  1. In first text component we are showing the current date from our mobile system into Month – Date – Year – Hour – Minute – Seconds with AM and PM format.
  2. In the Second text component we are showing the current Day name like Monday, Tuesday ETC.
  3. In the third text component we are showing current Date in Month – Date – Year format.
  4. In the forth text component we are showing current date in Date – Month – Year format.

Example of React Native Moment NPM Yarn Package

4. Now it’s time to explore more of Moment functions. Using the Moment we can easily convert one date format into another date format.

Example of React Native Moment NPM Yarn Package5. If you’re creating a CHAT based application then this might help you show previous year chats using these formats.

6. Now we can use Calendar method to retrieve the Date of previous day, next day and more. See the code example below.

We have cover most of Moment functions in our this tutorial. But there are a lot more on their official page. You can read them about HERE.