JavaScript Date Cheatsheet

JavaScript Date Cheatsheet

Hello Guuys!

Today I'll share with you JavaScript Date Cheatsheet,

JAVASCRIPT GET DATE METHODS

const todayDate = new Date();
todayDate; // Sun Dec 25 2022 02:22:41 GMT+0100 (GMT+01:00)

todayDate.getDate(); // 25
todayDate.getMonth(); // 11
todayDate.getHours(); // 2
todayDate.getFullYear(); // 2022
todayDate.getYear(); // 122
todayDate.getMinutes(); // 23
todayDate.getSeconds(); // 5
todayDate.getMilliseconds(); // 841
todayDate.getTime(); // 1671931470451

UTC - COORDINATED UNIVERSAL TIME

const todayDate = new Date();
todayDate; // Sun Dec 25 2022 02:32:46 GMT+0100 (GMT+01:00)

todayDate.getUTCDate(); // 25
todayDate.getUTCDay(); // 0
todayDate.getUTCMonth(); // 11
todayDate.getUTCFullYear(); // 2022
todayDate.getUTCHours(); // 1
todayDate.getUTCMinutes(); // 34
todayDate.getUTCSeconds(); // 19
todayDate.getUTCMilliseconds(); // 783

JAVASCRIPT SET DATE METHODS


const todayDate = new Date();
todayDate; // Sun Dec 25 2022 02:22:41 GMT+0100 (GMT+01:00)

todayDate.setDate(25); // Set the day as a number (1-31),
todayDate.setMonth(11); // Set the month (0-11)
todayDate.setFullYear (2022); // Set the year (optionally month and day)
todayDate.setHours(0); // Set the hour (0-23)
todayDate.setMinutes (0); // set the minutes (0-59)
todayDate.setSeconds (0); // Set the seconds (0-59)
todayDate.setMilliseconds (400); // Set the 11 seconds (8-999)
todayDate.setTime (40); // Set the time (mill1 seconds since January 1, 1970)

DATE STRING METHODS

const todayDate = new Date();
todayDate // Sun Dec 25 2022 02:43:25 GMT+0100 (GMT+01:00)

todayDate.toString(); // Sun Dec 25 2022 02:22:41 GMT+0100 (GMT+01:00)
todayDate.toDateString(); // Sun Dec 25 2022 
todayDate.toLocaleString(); // 12/25/2022, 2:43:25 AM
todayDate.toGMTString(); // Sun, 25 Dec 2022 02:43:25 GMT
todayDate.toUTCString(); // Sun, 25 Dec 2022 02:43:25 GMT

If you find it useful don't forget to Like and Follow for more.