Trying to create a new Date
object with the constructor new Date(24, 2, 1, 0, 0 ,0)
is causing an issue where it defaults to using setYear
instead of setFullYear
, resulting in the year being set as 1924. While this may work in most cases, I need the ability to set any given year.
Attempts to use a Date string format like Feb 2, 24 00:00:00
still resulted in the year 2024. Referencing the Date MDN documentation did not provide a successful workaround.
As a workaround, I opted for the following solution:
var d1 = new Date();
d1.setFullYear(y);
d1.setMonth(m);
d1.setDate(d);
d1.setHours(0);
d1.setMinutes(0);
d1.setSeconds(0);
However, this method is quite cumbersome and not ideal. I am curious if there is a better solution to this issue?