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

95
Vistas
How do I show the last visit on my website with a cookie?

The basic idea is that every time somebody visits the website the cookie saves the time and date. If the user then visits the website multiple times the cookie only shows the date and time when the user last visited. At the moment I have the following code which does work put obviously always updates the date and time:

var today = new Date();
var date = today.getDate()+'-'+(today.getMonth()+1)+'-'+today.getFullYear();
var time = today.getHours()+':'+today.getMinutes()+':'+today.getSeconds();
var dateTime = date+' at '+time;
document.cookie ='last_visit='+ dateTime 

Edit:For other people who might need help, the following code seems to work:

var today = new Date();
var date = today.getDate()+'-'+(today.getMonth()+1)+'-'+today.getFullYear();
var time = today.getHours()+':'+today.getMinutes()+':'+today.getSeconds();
var dateTime = date+' at '+time;
function getCookieValue(a) {
    const b = document.cookie.match('(^|;)\\s*' + a + '\\s*=\\s*([^;]+)');
    return b ? b.pop() : '';
}
console.log ("getCookieValue " + getCookieValue("last_visit"));
document.cookie ='last_visit='+ dateTime
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You cannot share visited data between users on the cookies without receiving data from the server.

The solution is to save the last visit DateTime into the Database and send it back to the client

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