Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Date | Set date to the last second of year

In javascript I have a Date object with the following value:

Thu Jan 01 1998 00:00:00 GMT+0100 (Central European Standard Time)

Year could be anything, but day and time is always Jan 01 00:00:00.

Question: How can I set the date to the last second of the chosen year? In this example: Dec 31 1998 23:59:59 GMT+0100 (Central European Standard Time)

like image 346
Vingtoft Avatar asked Dec 03 '22 18:12

Vingtoft


1 Answers

You can instantiate the Date object with this format:

new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]]);

Details here.

let date = new Date(1998,11,31,23,59,59); //note Month 11 is Dec (0 is Jan)
like image 114
chatnoir Avatar answered Dec 26 '22 07:12

chatnoir