如何在 node.js / loopback.io 上减去时间 -7 小时
How to subtract time -7 hours on node.js / loopback.io
我正在使用 Loopback 3 创建 API,我有这样的模型
Section.js
Section.js上
输出
我想把start_date减去-7小时,这样就变成这样了
...
"start_date": "2019-06-23T17:00:00.000Z",
...
我尝试使用此线程 How do I create getter and setter overrides? 中的 getter,就像这样
但是什么都没变,我是不是执行错了?
是 现在你必须在最后调用 Section.setup()
。这是默认的 User
模型。
基本上,
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(有错误):
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();
};
我正在使用 Loopback 3 创建 API,我有这样的模型
Section.js
Section.js上
输出
我想把start_date减去-7小时,这样就变成这样了
...
"start_date": "2019-06-23T17:00:00.000Z",
...
我尝试使用此线程 How do I create getter and setter overrides? 中的 getter,就像这样
但是什么都没变,我是不是执行错了?
是 现在你必须在最后调用 Section.setup()
。这是默认的 User
模型。
基本上,
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(有错误):
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();
};