在Mongodb 2.4版中将时间戳转换为ISO日期

时间:2019-07-18 07:59:46

标签: date mongodb-query

我安装了mongodb 2.4.10版本。该文档的结构是:-

{
    "_id" : ObjectId("5d15f245f4dda1e055091ae1"),
    "name" : "test site service", 
    "starFromTimestamp" : NumberLong(1559275200),
    "toTimestamp" : NumberLong(1561867200),
    "uuid" : "ssg-5d15f245f2893825813309"

}

我在Mongo shell中使用了以下代码,以便将时间戳转换为ISODate

db.servicesitegroup.find().forEach(function(doc) { 
    doc.startISODate=new Date(doc.starFromTimestamp);
    db.servicesitegroup.save(doc); 
    })

文档已更新,结果集如下:-

 {
    "_id" : ObjectId("5d15f245f4dda1e055091ae1"),
    "name" : "test site service", 
    "starFromTimestamp" : NumberLong(1559275200),
    "toTimestamp" : NumberLong(1561867200),
    "uuid" : "ssg-5d15f245f2893825813309",
    "startISODate" : ISODate("1970-01-19T01:07:55.200Z")    
  }

如果我使用时间戳转换器,则1559275200的值等于2019年5月31日星期五4:00:00 AM。为什么时间戳不能转换为正确的值?谁能在这里引导我。

1 个答案:

答案 0 :(得分:0)

我需要将时间戳记值乘以1000。

class myClass {
  constructor() {
    if ((<any>window).require) {
      try { ipc = (<any>window).require('electron').ipcRenderer; } catch (e) { throw e; }
    }
    else { console.warn('App not running inside Electron!'); }

    this._jar = request.jar();
    this._request = request.defaults({ jar: this._jar });
  }
}

上面的代码为我提供了正确的输出。

相关问题