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

136
Views
JS new Date() jump to next year

For a few days, I have had a problem with the date processed by JS, which would try to make the year jumps forward. A bit of sample code below.

Inicjal date in HTML 'Jan 19 2022'

  var dateYear = $(this).attr("dateYear");
  console.log('dateYear ' + dateYear); // dateYear 2022

  var dateMonth = $(this).attr("dateMonth");
  console.log('dateMonth ' + dateMonth); // dateMonth 12
  var dateDay = $(this).attr("dateDay");
  console.log('dateDay ' + dateDay); // dateDay 19
    
  var myDate = new Date(dateYear, dateMonth, dateDay);
  console.log('myDate ' + myDate); // myDate Thu Jan 19 2023 00:00:00 GMT+0000 (Greenwich Mean Time)

Even if it subtracts one index from a month, but the year jump to 2023, if the index of the month remains unchanged teddy data will be 'Feb 19 2022';

What could it be for two years there was no problem with the date.

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

0

This is JavaScript.

January is 0.

December is 11.

See Date.prototype.getMonth().

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!