Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda