简体   繁体   English

如何将两种不同的时间格式转换为一种格式的本机

[英]How to convert two different time format in one format react native

Below two dates am getting from api. 从API获取以下两个日期。 I have to convert both in 26-04-2019 12:45:43 PM" in this format . Please suggest 我必须在26-04-2019 12:45:43 PM中将两者都转换为这种格式。请提出建议

"26-APR-19 12:45", “ 26-APR-19 12:45”,

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

Thanks .. 谢谢 ..

You can use the momentjs library 您可以使用momentjs

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');

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

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