简体   繁体   English

在react.js中使用矩进行日期格式化

[英]Date formatting using moment in react.js

I have a date in a format below coming from the database. 我有一个以下格式的日期来自数据库。 Using react moment, I will like to convert the date to a format like this Sept-10-2018 我使用反应时间将日期转换为如下格式:Sept-10-2018

        2018-10-03T05:00:00.000+0000

I already added the import line below 我已经在下面添加了导入行

        import moment from 'moment'

How can I achieve this please? 请问我该如何实现?

Simply create a moment object by passing your string, then use the format method. 只需通过传递字符串即可创建一个矩对象,然后使用format方法。

 const date = moment('2018-10-03T05:00:00.000+0000'); console.log(date.format('MMM-DD-YYYY')); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.23.0/moment.js"></script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM