简体   繁体   中英

JavaScript: Convert “10/30/2015 2:43pm” to a Date object

As the title suggests, I need to know how to turn strings in the format of "10/30/2015 2:43pm" into JavaScript Date objects. The string comes from Datepair ( http://jonthornton.github.io/Datepair.js/ ) and I need to insert it into Mongo DB as a date. I've got Moment.js too if that's useful in this situation.

Thanks!

只需尝试:

new Date("10/30/2015 2:43pm".replace(/([ap]m)$/, " $1"))

使用力矩,只需提供格式作为第二个参数:

moment("10/30/2015 2:43pm", "MM/DD/YYYY hh:mma");

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