.isAfter return 偶为假

.isAfter return even false

我将 momentjsEonasdan 插件一起使用,我正在尝试检查 end 日期是否小于 start 日期,以便执行此操作我正在使用方法 isAfter:

var start = moment($('#start-datetime').val());
var end = moment($('#end-datetime').val());
console.log((start).isAfter(end));   

这将 return 甚至 false,值是这样定义的:

尝试将特定格式字符串和区域设置传递给 moment 以确保正确解析字符串:

moment(..., "DD/MM/YYYY HH:mm", "en");

moment.locale("en");
...
moment(..., "DD/MM/YYYY HH:mm");

示范:

moment.locale("en");
$("#test-button").click(function() {
  var start = moment($('#start-datetime').val(), "DD/MM/YYYY HH:mm");
  var end = moment($('#end-datetime').val(), "DD/MM/YYYY HH:mm");
  console.log((start).isAfter(end));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.23.0/moment.min.js"></script>
<input id="start-datetime" type="text" value="07/02/2019 19:58">
<input id="end-datetime" type="text" value="31/01/2019 19:58">
<button id="test-button">Test</button>