Comparing two times with Moment JS

后端 未结 4 921
[愿得一人]
[愿得一人] 2020-11-28 09:11

I have a problem that requires me to take two times in 12 hour format and compare them, we have moment.js included in our project and we initially thought it would be as tri

4条回答
  •  借酒劲吻你
    2020-11-28 09:37

    8:45am and 9:00am are invalid dates

    var beginningTime = moment('8:45am');
    var endTime = moment('9:00am');
    console.log(beginningTime.isValid(), endTime.isValid()) // FALSE
    

    You should use a valid format: http://momentjs.com/docs/#/parsing/string/

    And they suggest that for consistent results, should use http://momentjs.com/docs/#/parsing/string-format/

    Eg.

    moment("2010-10-20 4:30", "YYYY-MM-DD HH:mm"); // parsed as 4:30 local time
    

提交回复
热议问题