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

351
Vistas
Deterministic length of JS new Date().getTime() string in the modern era: Unix Epoch Time

console.log(new Date().getTime());

I have a silly question: In the modern era, is the length of JS new Date().getTime() always 13? Both JS and Java give time strings of this length.

My issue is that I have a random JS string created with

function generateUniqueID() {
    return new Date().getTime() + '' + Math.round(Math.random() * Math.pow(10,6));
}

This string concatenates a Time string with a random number. I need to compare 2 IDs to see which one is for an earlier Date. But the random part of this string isn't always a 6-digit number, so I can't truncate the trailing 6 digits and consider that the time string. To get the time string, I can consider the first 13 digits. That seems to be the Unix Epoch Time string in the modern era.

But is that reliable? When would getTime() start giving 14 digits?

Also, if I look up Unix Epoch Time on Wikipedia, I see a 10-digit number as the current Unix Time, not 13-digit: 1637093681. https://en.wikipedia.org/wiki/Unix_time

Updated I see the length changes at this point: 2281-11-20 and 2281-11-21

console.log(new Date('2286-11-20').getTime().toString().length);
console.log(new Date('2286-11-21').getTime().toString().length);

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

0

The timestamp is milliseconds since 1970-01-01 00:00:00 UTC (the same as the Unix epoch). Subtract the current timestamp from 10000000000000 to get the number of milliseconds until it overflows to 14 digits, which is 8,362,906,319,000. Then divide this by the number of milliseconds in a year, which is about 31,557,600,000, to get the number of years until it reaches that value.

This is about 265 years.

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