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

266
Vistas
JavaScript Date constructor returns invalid date in CMS (server-side JS)

I'm making an React app where I query Microsoft Graph API where I get the response date 2021-11-03T07:45:00.0000000.

When I try to convert it to a JavaScript Date like this it gives me "invalid date" on let date = new Date(dateString);

    let dateString = "2021-11-03T07:45:00.0000000"
    let date = new Date(dateString);
    let timezoneOffset = date.getTimezoneOffset();
    date.setMinutes(date.getMinutes() - timezoneOffset);
    let hours = date.getHours();
    let minutes = date.getMinutes();
    let formattedMinutes = minutes > 9 ? minutes : '0' + minutes;  
    console.log(hours + ':' + formattedMinutes); 

This works in normal JS but the problem is that I use a CMS (server-side JS) that doesn't support new Date(dateString) so is it possible to format the date value to 8:45 without using Date constructor in JS? (npm libraries work in the CMS so if you have any solution with third party libraries it's fine.)

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

0

A regex could help in this situation. This is a simple example when there is no timezone offset.

str = '2021-11-03T07:45:00.0000000'

const time = str.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}T([0-9:]{5})/)[1]

const timeFormatted = time.split(':').map(num => parseInt(num)).reduce((timeFormatted, num) => {
  if (timeFormatted) timeFormatted += ':'
  timeFormatted += num
  return timeFormatted
})

console.log(timeFormatted)

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