Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!