Javascript New Date Showing Wrong Date

I have encountered a client today to fix a countdown issue which is running on JavaScript. The problem is when the client changed the date, it display the wrong date.  The countdown script was using a Javascript object called  new Date(). This issue reminded me of my subject called “Logicom” in college because the logic behind the issue is because new Date() uses a different logic in counting date. Normally, if we do counting, it starts with one (1) wherein new Date() it starts with zero(0).

To solve the New Date Showing Wrong Date is to simply apply the logic of JavaScript counting which mean you should start counting date from zero instead of one. See example below

new Date(2018, 05, 30);    // In our logic this would be May 30, 2018 but in JavaScript, it would be June 30, 2018 since the count starts at 0 instead of 1.

 

Leave a Comment

Your email address will not be published. Required fields are marked *