react 日期格式化_使用Moment js在React js中格式化日期或时间

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)

  1. 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 日期格式化

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值