react 日期格式化
Today in this tutorial I'll help you in formatting your date or time in React js. For this, we’ll be using a library called moment js.
今天,在本教程中,我将帮助您在React js中格式化日期或时间。 为此,我们将使用一个名为moment js的库。
A lightweight JavaScript date library for parsing, validating, manipulating, and formatting dates.
一个轻量级JavaScript日期库,用于解析,验证,操作和格式化日期。
要求 (Requirements)
- Open your project directory and install moment js. 打开项目目录并安装moment js。
npm i moment --save
2. Open app.js file and import moment from moment.
2.打开app.js文件并时刻导入。
import moment from 'moment'
3. Now all you need is to pass your timestamp or date format to the moment method.
3.现在,您需要做的就是将时间戳或日期格式传递给moment方法。
moment('timestamp').format('MMMM Do YYYY')Example : moment('20010704T120854').format('MMMM Do YYYY')
Below are the Github repository and live code for reference.
以下是Github存储库和实时代码以供参考。
翻译自: https://medium.com/how-to-react/format-your-date-or-time-in-react-js-using-moment-js-89c5c6e4f174
react 日期格式化