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

225
Vistas
Passing a string to new Date() constructor results in Invalid Date

How can I pass a string date from a variable to the new Date(...) constructor? The following code produces Invalid Date. Do I need to convert it first somehow?

var dateString = '18/11/2021';
var dateObject = new Date(dateString);
alert(dateObject);

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

0

When using the Date(dateString) constructor, the date string must be specified in simplified ISO 8601 date format. Also note that conforming date only formats such as yyyy-mm-dd are treated as UTC, not local. The following should produce the expected result:

alert(new Date("2021-11-18T00:00:00"));

Using any non-standard format is discouraged and the results are implementation specific.

about 4 years ago · Juan Pablo Isaza Denunciar

0

it's your dateString format. First the year, month and then day.

hello = '2021/11/18';
end = new Date(hello);
alert(end);

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