MomentJS:如何解析MM / DD / YYYY&中的日期DD / MM / YYYY [英] MomentJS: how to parse dates in MM/DD/YYYY & DD/MM/YYYY
问题描述
我如何在两者中使用moment.js:澳大利亚&美国时间格式?
How can i use moment.js in both: Australia & USA time formats?
例如:
07/08/2017
- 适用于两种时间格式,但是!
07/08/2017
- is good for both time formats, but!
30/08/2017
- 是对于moment.js无效,但我可以有这样的日期时间
30/08/2017
- is invalid for moment.js, but i can have such dateTime
你可以在这里查看:
http://jsfiddle.net/rLjQx/2135/
推荐答案
解析器假设XX-XX-XXXX形式的数字代表DD-MM-YYYY。如果你想接受MM-DD-YYYY那么你需要指定它。
The parser is assuming that digits of the form XX-XX-XXXX are representing DD-MM-YYYY. If you'd like it to accept MM-DD-YYYY then you need to specify this.
例如 var now2 = moment('08 / 30/2017','MM-DD-YYYY')。格式('MMM DD h:mm A');
你可以还指定了一个您希望它接受的不同格式的数组,以便它能识别两者:
You can also specify an array of different formats that you'd like it to accept so that it will recognise both:
var now2 = moment('08 / 30/2017',['DD-MM-YYYY','MM-DD-YYYY']。格式('MMM DD h:mm A');
这篇关于MomentJS:如何解析MM / DD / YYYY&中的日期DD / MM / YYYY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!