简体   繁体   中英

How to convert two different time format in one format react native

Below two dates am getting from api. I have to convert both in 26-04-2019 12:45:43 PM" in this format . Please suggest

"26-APR-19 12:45",

"26/04/2019 12:45:43"

Thanks ..

You can use the momentjs library

Example:

import moment from 'momentjs'
...
date_one = moment("26-APR-19 12:45","DD-MMM-YY HH:mm")
date_two = moment("26/04/2019 12:45:43","DD/MM/YYYY HH:mm:ss")
console.log(date_one).format("DD-MM-YYYY hh:MM:SS A") //  26-04-2019 12:45:43 PM
console.log(date_two).format("DD-MM-YYYY hh:MM:SS A") //  26-04-2019 12:45:43 PM

只需使用Moment.js例如

moment('26-APR-19 12:45').format('MMMM Do YYYY, HH:MM:SS A');

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