JScript日期比较

时间:2011-05-02 21:51:17

标签: javascript

var FSO     = new ActiveXObject("Scripting.FileSystemObject");
var BFolder = "C:\\temp";
var XFolder = FSO.GetFolder(BFolder+"\\");
var FList   = new Enumerator(XFolder.Files);
var today   = new Date();

for (; !FList.atEnd(); FList.moveNext()) {

   var d = FList.item().DateLastModified;
   if (d.getMonth() == today.getMonth) { // <----- *

   }
   else {

   }
}

如何使上述比较(*)有效?

2 个答案:

答案 0 :(得分:2)

您应该使用today.getMonth()代替today.getMonth 也许替换

var d = FList.item().DateLastModified;

通过

var d = new Date(FList.item().DateLastModified);

答案 1 :(得分:0)

假设dDate个对象,您可以这样比较几个月:

if (d.getMonth() == today.getMonth()) { …

(您需要致电 Date.getMonth)。