首页 > 解决方案 > 在javascript和角度中向日期添加秒的地方

问题描述

我正在尝试在日期中添加第二个。

我尝试:

var g = this.endTime;

console.log(g); // output : Wed Sep 15 2021 15:35:00 GMT+0300 (Eastern European Summer Time)

this.endTime = null;

this.startTime = null;

this.startTime = new Date(g.setSeconds(g.getSeconds() + this.timeFromGoogle));

console.log(this.startTime); // output: Wed Sep 15 2021 15:42:57 GMT+0300 (Eastern European Summer Time)

var temp = this.startTime;

console.log(temp); // output: Wed Sep 15 2021 15:42:57 GMT+0300 (Eastern European Summer Time)

this.endTime = new Date(temp.setSeconds(temp.getSeconds() + (resp.data.locations[0].stay_limit * 60)));

console.log(this.endTime); // output: Wed Sep 15 2021 15:45:57 GMT+0300 (Eastern European Summer Time)

console.log(this.startTime); // output: Wed Sep 15 2021 15:45:57 GMT+0300 (Eastern European Summer Time)

console.log(temp); // output : Wed Sep 15 2021 15:45:57 GMT+0300 (Eastern European Summer Time)

this.timeFromGoogle= 数字(秒)。

resp.data.locations[0].stay_limit=数字(分钟)。

正如我们看到 startTime 在开始时工作正常,而 endTime 也但是:

添加后:

this.endTime = new Date(temp.setSeconds(temp.getSeconds() + (resp.data.locations[0].stay_limit * 60)));

this.startTime 改变,和他的 endTime 值一样。

为了解决这个问题,我使用 temp 在其上存储 startTime 以在 endTime 中使用 temp,但也不起作用。

输出应该是:

startTime: Wed Sep 15 2021 15:42:57 GMT+0300 (Eastern European Summer Time).

endTime: Wed Sep 15 2021 15:45:57 GMT+0300 (Eastern European Summer Time).

我不知道为什么添加 endTime 查询后 startTime 的值会发生变化?

标签: javascriptangulardatedatetime

解决方案


推荐阅读