简体   繁体   中英

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

        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.

 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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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