简体   繁体   English

Moment.js如何将MM / dd / yyyy HH:mm:ss.fff转换为往返日期/时间模式?

[英]Moment.js How to convert MM/dd/yyyy HH:mm:ss.fff to round-trip date/time pattern?

如何通过使用标准JavaScript或moment.js库将字符串"8/3/2017 6:12:00 AM""2017-08-03T06:12:00.000"

您可以通过以下方式使用矩将8/3/2017 6:12:00 AM转换为2017-08-03T06:12:00.000

moment("8/3/2017 6:12:00 AM", 'DD/MM/YYYY HH:mm:ss a').format('YYYY-DD-MMTHH:mm:ss.000')

 console.log(moment("8/3/2017 6:12:00 AM", 'DD/MM/YYYY HH:mm:ss a').format('YYYY-DD-MMTHH:mm:ss.000')) 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script> 

if you know what format you are getting then i suggest to parse and create an js date object. 如果您知道要获取的格式,则建议解析并创建一个js日期对象。 and then 接着

 var year = 2017; var month = 2; var day = 8; var date = new Date(year, month, day); console.log(date.toISOString()); 

Updated: 更新:

 console.log(moment("8/3/2017 6:12:00 AM", 'DD/MM/YYYY HH:mm:ss a').format('YYYY-DD-MMTHH:mm:ss.000')) 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script> 

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

相关问题 如何使用moment.js将秒传输到时间格式(YYYY:MM:DD HH:mm:ss) - How to transfer seconds to Time format (YYYY:MM:DD HH:mm:ss) using moment.js 当日期为MM / DD / YYYY HH:mm:ss时,moment.js从现在的日期返回意外 - moment.js returning an unexpected fromNow date when date is MM/DD/YYYY HH:mm:ss 使用 Iso yyyy-MM-dd HH:mm:ss 的无效日期 moment.js - Invalid Date moment.js using Iso yyyy-MM-dd HH:mm:ss 使用moment.js(时区)时以(“ YYYY-MM-DD HH:mm”)格式返回日期和时间 - Return date and time in (“YYYY-MM-DD HH:mm”) format when using moment.js (timezone) 如何在 moment.js 中将秒转换为 HH:mm:ss - How to convert seconds to HH:mm:ss in moment.js 使用 moment.js 将日期转换为字符串“MM/dd/yyyy” - Using moment.js to convert date to string “MM/dd/yyyy” Moment.js转换MM / dd / yyyy格式日期 - Moment.js convert MM/dd/yyyy format date 在moment.js中将“ yyyy-mm-ddThh:mm-offset”格式转换为“ yyyy-mm-dd HH:mm” - Convert 'yyyy-mm-ddThh:mm-offset' format to 'yyyy-mm-dd HH:mm' in moment.js 如何在js中将MM/dd/yyyy HH:mm:ss zzz格式的字符串转换为日期 - How to convert string of MM/dd/yyyy HH:mm:ss zzz format to date in js 如何使用 moment 或 js 将 DD-MM-YYYY HH:mm 格式转换为纪元时间? - How to convert the DD-MM-YYYY HH:mm format to epoch time using moment or js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM