简体   繁体   English

如何将 Sharepoint 列表视图中的两个日期与 javascript 进行比较?

[英]How do I compare two dates in Sharepoint listview with javascript?

I want to compare two dates in a sharepoint list using javascript.我想使用 javascript 比较 sharepoint 列表中的两个日期。 2 years ago I asked a question about comparing two dates in sharepoint. 2 年前,我问了一个关于比较 sharepoint 中的两个日期的问题。 The code I use is this:我使用的代码是这样的:

var date = new Date(listItem.LTIOV);
var todaysDate = new Date();

if ((date < todaysDate) && (listItem.MijnStatus == "In Action")) {
    if (row != null){
        row.style.backgroundColor = "rgba(153, 204, 255, 0.5)"; //light blue
    }
}

Back then is worked because the date in listitem.LTIOV was only a date and no time.那时可以工作,因为 listitem.LTIOV 中的日期只是一个日期,没有时间。 This time my date also has a time part in it.这次我的约会也有时间部分。 I already tried with date.GetTime() but the results are not correct.我已经尝试过 date.GetTime() 但结果不正确。 Some dates come back with a year in the future like 2022.有些日期会在未来一年(例如 2022 年)返回。

Anyone know how to do this?有人知道怎么做吗?

Marco马可

The new Date(listItem.LTIOV) would also get the time, if you don't have time in listitem.LTIOV, it would return as in 00:00:00 for the time. new Date(listItem.LTIOV)也将获取时间,如果您在 listitem.LTIOV 中没有时间,它将返回时间为 00:00:00。

So, you could compare two dates with time like this:因此,您可以像这样比较两个日期和时间:

var date = new Date(date1);
var date = new Date(date2);
if(date1<date2){

}

Reference:参考:

https://www.w3schools.com/js/js_date_methods.asp https://www.w3schools.com/js/js_date_methods.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM