An Interest In:
Web News this Week
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
- April 18, 2024
September 22, 2021 01:19 am GMT
Original Link: https://dev.to/iamadeyemiadex/formatting-dates-in-react-js-with-fns-2mpg
Formatting Dates in React Js with fns
If you are new to reactjs, you will agree with me that date format is quite different from that of core javascript where what is needed to do is just writing a simple date object: new Date()
.
However in the modern day JavaScript library which is reactjs, getting and formatting date is quite different. Though there are ways to format dates, but I will show you the simplest way you can go about it.
- 1 install npm date-fns in your project directory (root directory)
C:\MyProjects\react-project>npm install date-fns
- 2 use import { format } from 'date-fns' within your component
import { format } from 'date-fns'
- 3 use the new Date() object within your component
Now, after doing 2 and 3 as mentioned above, you can then make use of the Date() and format it as you wish. For example:
{format ( new Date(), 'do MMMM Y')}
This will give us the current date. Example: 22 SEPTEMBER 2021
Original Link: https://dev.to/iamadeyemiadex/formatting-dates-in-react-js-with-fns-2mpg
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To