(XPages)如何编写代码来计算日期之间的天数?

(XPages)How can I write the code for calculate the number of days between dates?

我有一个字段名,叫做"REF_DATE""REF_DATE"'s 格式为 "YYYY/MM/DD"

我需要计算从今天到"REF_DATE"的天数。

例如:

REF_DATE = 2020/01/09

Today = 2020/04/01

以下是我试过的代码:

var s1 = "2020/01/09";
var s2 = "2020/04/01";
var aDate = s1.split("/");
var oDate1 = Date.UTC(aDate[1],aDate[2],aDate[0]);
var bDate = s2.split("/");
var oDate2 = Date.UTC(bDate[1],bDate[2],bDate[0]);
var iDays = Math.floor((oDate2 - oDate1)/86400000);
return oDate1+"<br>"+oDate2+"<br>"+iDays+"<br>";

但是 xpages 显示 "853"

所以,我需要你们帮助我如何计算日期之间的天数。

谢谢!!!!!!

将年份作为第一个 Date.UTC 参数传递并从月份中减去 1(0 是一月):

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
<xp:this.beforePageLoad><![CDATA[#{javascript:
    var s1 = "2020/01/09";
    var s2 = "2020/04/01";
    var aDate = s1.split("/");
    var oDate1 = Date.UTC(Number(aDate[0]), Number(aDate[1]-1), Number(aDate[2]));

    var aDate = s2.split("/");
    var oDate2 = Date.UTC(Number(aDate[0]), Number(aDate[1]-1), Number(aDate[2]));

    var iDays = Math.floor((oDate2 - oDate1) /1000/60/60/24);
    print(iDays);
}]]></xp:this.beforePageLoad>
</xp:view>