如何减去时间-node.js/loopback.io上的7小时

如何减去时间-node.js/loopback.io上的7小时,node.js,loopbackjs,Node.js,Loopbackjs,我使用loopback3创建API,我有这样的模型 ... "start_date": "2019-06-23T17:00:00.000Z", ... Section.js Section.json 输出 我想把开始日期减到-7小时,这样它就变成这样了 ... "start_date": "2019-06-23T17:00:00.000Z", ... 我试着像这样使用这个线程中的getter ... "start_date": "2019-06-23T17:00:00.000Z", ...

我使用loopback3创建API,我有这样的模型

...
"start_date": "2019-06-23T17:00:00.000Z",
...
Section.js

Section.json

输出

我想把开始日期减到-7小时,这样它就变成这样了

...
"start_date": "2019-06-23T17:00:00.000Z",
...
我试着像这样使用这个线程中的getter

...
"start_date": "2019-06-23T17:00:00.000Z",
...

但是什么都没有改变,我是否执行错误?

是的,现在您必须在最后调用Section.setup。这是默认的用户模型

所以基本上

module.exports = function(User) {


  User.setup = function() {
    // We need to call the base class's setup method
    User.base.setup.call(this);
    var UserModel = this;
    UserModel.setter.email = function(value) {
      if (!UserModel.settings.caseSensitiveEmail) {
        this.$email = value.toLowerCase();
      } else {
        this.$email = value;
      }
    };

    return UserModel;
  };

  /*!
   * Setup the base user.
   */

  User.setup();
};
我不知道该怎么做,但我做了一个MCVE,似乎可以处理bug:

module.exports = function(Some) {
    Some.setup = function() {
        Some.base.setup.call(this);
        var UserModel = this;
        Some.getter.name = function(){
            console.log(this.$name);
            return this.$name+"lol";
        }
    }
    Some.setup();
};

很好,现在开始日期已更改,但始终显示为空。我尝试使用console.logvalue打印函数中的值;但我没有定义。为什么值返回未定义?因为getter不需要参数,setter需要它们。如果getter不需要参数,如何获取start\u date值并减去它们?你能给我举个例子吗?编辑了答案。