Monday, February 26, 2024
 Popular · Latest · Hot · Upcoming
129
rated 0 times [  136] [ 7]  / answers: 1 / hits: 17346  / 7 Years ago, fri, july 7, 2017, 12:00:00

How can i use moment.js in both: Australia & USA time formats?



For example:



07/08/2017 - is good for both time formats, but!



30/08/2017 - is invalid for moment.js, but i can have such dateTime



You can check it here:



http://jsfiddle.net/rLjQx/2135/


More From » datetime

 Answers
10

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.



eg var now2 = moment('08/30/2017', 'MM-DD-YYYY').format('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']).format('MMM DD h:mm A');


[#57175] Thursday, July 6, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aubriea

Total Points: 641
Total Questions: 118
Total Answers: 101

Location: French Southern and Antarctic Lands
Member since Fri, Jan 6, 2023
1 Year ago
;