Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

73
Vistas
Updating Date object to now()

I need to read the current time in one second intervals.
Should I rely on garbage collection to take care of regularly created instances of Date like mytime = new Date() or should I update mytime with the static Date.now() - and how?


Put differently:
let mytime = new Date();
...
// regularly
// A)
mytime = new Date(); // replace with current instance, rely on garbage collection
// OR
// B)
mytime.setUTCMilliseconds(Date.now()); // update original instance
7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Unless for some reason you need to make sure that you have only a single shared instance and that it gets mutated (hint: you really shouldn't), just create new date objects whenever you need them. GC will take care of the old ones just fine.

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos