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

227
Views
Javascript Date Object Off by One Month

I understand that javascript counts the months starting from 0. However, I don't know how to account for this when getting a date in the future.

For example, when attempting to get the date for tomorrow, the following code returns everything correct except for the month (prints as next month):

const weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
const month =  ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

var today = new Date();
today.setUTCDate(today.getUTCDate()+1);

let newDate = weekday[today.getDay()] +' '+today.getDate()+' '+month[today.getDay()]+', '+ today.getFullYear();

console.log(newDate)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just replace today.getDay() to today.getMonth()

const weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
const month =  ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

var today = new Date();
today.setUTCDate(today.getUTCDate()+1);

let newDate = weekday[today.getDay()] +' '+today.getDate()+' '+month[today.getMonth()]+', '+ today.getFullYear();

console.log(newDate)

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!