Estoy tratando de agregar un segundo a una fecha.
lo intento:
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 = número (segundo).
resp.data.locations[0].stay_limit = número (minuto).
Como vemos, startTime funciona bien al principio, y endTime también, pero:
después de agregar esto:
this.endTime = new Date(temp.setSeconds(temp.getSeconds() + (resp.data.locations[0].stay_limit * 60)));this.startTime cambia, y es lo mismo que el valor de endTime.
para solucionar esto, uso temp para almacenar startTime en él para usar temp en endTime, pero tampoco funciona.
la salida debe ser:
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).No sé por qué el valor de startTime cambia después de agregar la consulta endTime.