• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

173
Vistas
Daily info using setTimeout?

How can I use setTimeout to display a new Text daily, every 24 hours The code below is wrong It's just to draw attention to the images I want to display enter image description here

almost 3 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Dont use setTimeout function if you want to show quotes daily because when you will close your application then setTimeout will vanished as it will not run in background or when you will reload App then it will also reset. So its not good practice to use it for that purpose. If you want to show random quotes daily then make a backend and here you have to write CRON Job for it which will be executed after 24 hours and save quotes in your DB. And then load these quotes (by making backend route) from your DB on client side. However if you want to use the background timers then use them instead of setTimeout.

almost 3 years ago · Juan Pablo Isaza Denunciar

0

As Asad Haroon suggested, you may use crontab with a cronjob that looks something like this: 0 0 * * * or @daily. Apart from that, you may consider using anacron as well if you are not sure your backend runs non-stop 24/7 (but the config is different then).

But I want to suggest another implementation. You can try to record the last time (like formatted new Date()) your user opened the website and saw the quote. If you don't have a backend, you can store it using localStorage: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

Once the user opens the website again, you check if 24 hours has passed since the last quote update. Say, subtract one date and time from the other. If it has, update the quote. Otherwise, don't do anything.

To summarize, make this calculation every time your user opens the website and check if 24 hours has passed since the last quote update by subtracting current date and time from the last quote update ones.

almost 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda