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

211
Vistas
How to get Month-Year from a string of timestamp?

I want to get the Month & Year from a string of Timestamp.

Attempted:

 var x =  "2021-09-08T17:00:00.000Z"
 
 x.toLocaleString('en-us',{month:'short', year:'numeric'})
 
 console.log(x)`enter code here`

Expected result

x = "September 2021"
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can easily achieve this result using getMonth() and getFullYear() method of Date object

const x = "2021-09-08T17:00:00.000Z";

const monthNames = [
  "January",
  "February",
  "March",
  "April",
  "May",
  "June",
  "July",
  "August",
  "September",
  "October",
  "November",
  "December",
];

const date = new Date(x);
const result = `${monthNames[date.getMonth()]} ${date.getFullYear()}`;
console.log(result);

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can edit your code as follows

var x = "2021-09-08T17:00:00.000Z"

var monthYear = new Date(x).toLocaleString('en-us', {
  month: 'long',
  year: 'numeric'
})

console.log(monthYear)

about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to first parse it as a date object.


 const x =  "2021-09-08T17:00:00.000Z"
 const y = new Date(x)

then you can use the date methods.


console.log(y.toLocaleString("en-us", { month: "long", year: "numeric" }));

outputs: September 2021

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