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

230
Vistas
How to convert JSON Date to Month in JavaScript

I have JSON Data from my Appscript REST API, how can I convert the date to be a month in number eg if the date contains 01 I only obtain 1/or instead of "2020-01-15T22:00:00.000Z

Here is the data sample below:

{
"Employee Name":"Ntombi  Hlatshwayo",
"Issueing Manager":"Nomsa Nxumalo",
"Type Of A Warning":"Insubordination Final",
"Date":"2020-09-15T22:00:00.000Z",
"Current Date":"2021-11-02T12:24:32.428Z",
 "Status":413
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use the Date() constructor to parse the dates since they are in ISO format, then use getUTCMonth() to get the month index. The month number will be one greater than this.

You can also use String.split() to get the same value.

let o = {
    "Employee Name":"Ntombi  Hlatshwayo",
    "Issueing Manager":"Nomsa Nxumalo",
    "Type Of A Warning":"Insubordination Final",
    "Date":"2020-09-15T22:00:00.000Z",
    "Current Date":"2021-11-02T12:24:32.428Z",
     "Status":413
}

function getMonthFromISODate(dt) {
   return new Date(dt).getUTCMonth() + 1;
}
 
console.log('Using Date()');
for (let dt of [o.Date, o['Current Date']]) { 
    console.log(`Date: ${dt}, Month: ${getMonthFromISODate(dt)}`);
}

function getMonthFromISODateII(dt) {
   return +dt.split('-')[1];
}
 
console.log('Using String.split()');
for (let dt of [o.Date, o['Current Date']]) { 
    console.log(`Date: ${dt}, Month: ${getMonthFromISODateII(dt)}`);
}
.as-console-wrapper { max-height: 100% !important; top: 0; }

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