Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 比较日期对象不起作用_Javascript_Meteor - Fatal编程技术网

Javascript 比较日期对象不起作用

Javascript 比较日期对象不起作用,javascript,meteor,Javascript,Meteor,我有这个JS代码,我想比较2时间对象: Meteor.setInterval( function () { productDate = Products.findOne({}); var timeNow = Date(); var timeCreated = productDate.createdAt var productId = productDate._id; productDate = Products.findOne({}); conso

我有这个JS代码,我想比较2时间对象:

 Meteor.setInterval( function () {
  productDate = Products.findOne({});
    var timeNow = Date();
    var timeCreated = productDate.createdAt 
    var productId = productDate._id;
    productDate = Products.findOne({});
    console.log(timeNow + " time now")
    console.log(timeCreated + " time when created")



        if (timeCreated <= timeNow) {
          console.log("working");
          console.log(productId);
          console.log(this.id);
        Products.update({_id: productId}, {$set: {isItReady: true}})

    }
  }, 5000);
这些只是前两个输出

基本上我想知道什么时候timeCreated小于timeNow,然后再做点什么。当我用
typeOf
检查两个变量
timeNow
timeCreated
时,它返回这两个变量的
Object


有什么问题,为什么我在检查
(timeCreated您的timeNow变量是否是字符串而不是日期对象后没有访问console.log

timeNow = new Date();  // this is a date object
timeNow = Date();      // this is a string value with current date

我不确定您创建的时间的类型,但这也需要是日期对象或转换为用于检查。

并且您确定数据库正在返回日期对象?无所谓。字符串表示也应该有效。
I20150423-18:55:09.950(3)?2015年4月23日周四18:55:09 GMT+0300(EEST)
is>than
I20150423-18:55:09.950(3)?2015年4月23日星期四18:52:52 GMT+0300(EEST)
try.toString()在对象上运行。奇怪的是,对象比较不起作用。作为测试,你能尝试
如果((新日期(timeCreated.toString())这是正确的。我做了检查,timeNow=new Date();返回一个对象,该对象可与来自我的数据库的对象进行比较。
timeNow = new Date();  // this is a date object
timeNow = Date();      // this is a string value with current date