Tengo datos JSON de mi API REST de Appscript, ¿cómo puedo convertir la fecha para que sea un mes en número, por ejemplo, si la fecha contiene 01, solo obtengo 1/o en lugar de "2020-01-15T22: 00: 00.000Z
Aquí está la muestra de datos a continuación:
{ "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 }Puede usar el constructor Date() para analizar las fechas, ya que están en formato ISO, luego use getUTCMonth() para obtener el índice del mes. El número del mes será uno mayor que este.
También puede usar String.split() para obtener el mismo valor.
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; }