By the Date Objects in JavaScript we will can get the current date and time and format the date according to our desire output. In the example below we will learn how we can get current date also we can put some date in date parameter and will convert it to date format.
JavaScript Date Objects let us work with dates
Sun Oct 01 2023 21:12:59 GMT+0530 (India Standard Time)
Creating Date Objects
new Date()
new Date(date string)
new Date(year,month)
new Date(year,month,day)
new Date(year,month,day,hours)
new Date(year,month,day,hours,minutes)
new Date(year,month,day,hours,minutes,seconds)
new Date(year,month,day,hours,minutes,seconds,ms)
new Date(milliseconds)
Code
const d = new Date();
const d1 = new Date("October 01, 2023 12:11:00");
const d2 = new Date(2023, 12, 24, 11, 31, 20, 0);
console.log(d1);
console.log(d2);
console.log(d3);
Output
Sun Oct 01 2023 21:20:12 GMT+0530 (India Standard Time)
Sun Oct 01 2023 12:11:00 GMT+0530 (India Standard Time)
Wed Jan 24 2024 11:31:20 GMT+0530 (India Standard Time)
Thanks.