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

224
Vistas
How to prevent time change on refresh after displaying once?

How to prevent time change on refresh after displaying once? Trying to achieve the time to be saved once upon generating each html.

const d = new Date();
let text = d.toLocaleTimeString();
document.getElementById("time").innerHTML = text;
<div>
    <b>Time Generated: </b><span style="padding-right:410px" id='time'</span>
</div>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can save the date on the Session storage or Local storage

i choose the first one for this example, but you need to know that Session storage only persists for as long as the current browsing session and is cleared as soon as the browser is closed, if ou want a long term storage you need to use Local Storage.

First check if is the first time on the page:

sessionStorage = window.sessionStorage;    
if (!sessionStorage.getItem('date')) {
  sessionStorage.setItem('date', new Date().toLocaleTimeString());
}

And then get the date:

text = sessionStorage.getItem('date');
document.getElementById("time").innerHTML = text;

I hope it helps you, have a nice day!

about 4 years ago · Juan Pablo Isaza Denunciar
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