javascript - 在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 的值会发生变化?
解决方案
推荐阅读
- mysql - PHP MYSQL 从数据库中返回最近 3 个月的日期 - Mysql Query
- python - 如何使用 JWT 身份验证在 rest_framework 中注销?
- typescript - 类型“HierarchyNode”上不存在属性“x”
' - javascript - gatsby-react-helmet 生成空
on SSR</h1> <div id="body"><p>My Gatsby website is not generating proper title tags on SSR. When I build the website all I get on my generated files are <code><title data-react-helmet="true">< - reactjs - 在测试反应应用程序期间,样式是“未定义”的
- linux - Bash“file --mime-type”命令在 Perl 脚本中不起作用
- java - 忽略 MS Access SELECT DISTINCTROW 中的某个列
- r - R 的 heatmap2 包中多个热图的通用图例和标题
- python - 使用 python、selenium 和美丽的汤从 airbnb 获取数据
- spring - 如何在 JPA 存储库中使用规范编写自定义 findAll()