Mastering date manipulations using JavaScript Object
Methods
const today = new Date();
console.log(today)
Fri Feb 09 2024 21:01:32 GMT+0600 (Bangladesh Standard Time)
console.log(today.getDate()); // Current day of the month
9
console.log(today.getMonth()); // Current month (0-11, where O is January)
1
console.log(today.getFullYear()); // Current year
2024
console.log(today.getHours()); // Current hour (0-23)
21
console.log(today.getMinutes()); // Current minute (0-59)
1
console.log(today.getSeconds()); // Current second (0-59)
32
console.log(today.getMilliseconds()); // Current Millisecond
535
console.log(today.toDateString()); // Current date string
Fri Feb 09 2024
console.log(today.toGMTString()); // Current date time of the GMT
Fri, 09 Feb 2024 15:01:32 GMT
console.log(today.toISOString()); // Current date time of the Local Time Zone
2024-02-09T15:01:32.535Z
console.log(today.toLocaleDateString()); // Current date string of the Local Time Zone
2/9/2024
console.log(today.toLocaleString()); // Current date time of the local time zone
2/9/2024, 9:01:32 PM
console.log(today.toLocaleTimeString()); // Current time string of local time zone
9:01:32 PM
console.log(today.getUTCHours()); // Current hour of UTC
15
console.log(today.toJSON()); // Current date time JSON
2024-02-09T15:01:32.535Z