Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
conflicto donde agregar segundo a una fecha en javascript y angular

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.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda