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

163
Vistas
Angular converting string to date error invalid

I am getting a date in the form of string date: '2022-07-15T09:29:24.958922Z[GMT]', When I convert it in to date then I get error invalid date. Does someone know how to solve it?

   const myDate = response; // '2022-07-15T09:29:24.958922Z[GMT]'
   this.transactionDate = new Date(myDate);

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

So the problem is [GMT] in your response string.

Either your response should be something like this

new Date("Fri Jan 20 2022 11:51:36 GMT-0500")

or you need to remove [GMT] from your existing string

 var datestring ='2022-07-15T09:29:24.958922Z[GMT]';
 datestring.substr(0,datestring.indexOf('['));
 new Date(datestring)

var withGMT = new Date("Fri Jan 22 2022 11:51:36 GMT-0500")
console.log(withGMT);

var dateString ='2022-07-15T09:29:24.958922Z[GMT]';
var withoutGMT=dateString.substr(0,dateString.indexOf('['));
console.log(new Date(withoutGMT))

about 4 years ago · Santiago Gelvez 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