let now = new Date(); // milliseconds since Jan 1, 1970
let date = new Date(date string); // creates a date from a date string
new Date(year,month) // JS Counts months from 0 to 11. No errors adds overflow into next year
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) // in order
new Date(milliseconds) // can’t omit month, will store ms since Jan, 01, 1970.
The javascript date object lets you use real time. Uses UTC but works with time from local time zone.
now.toDateString() // converts a date into a more readable format. Thu Mar 30 2023
now.toUTCString() // converts a date into string in UTC Standard Thu, 30 Mar 2023 20:11:10 GMT
now.toISOString() // 2023-03-30T20:11:34.687Z
Get Methods: Return Local Time:
now.getFullYear() // get year as a four digit number (yyyy)
now.getMonth() // get month as a number (0 - 11)
now.getDate() // get day as a number (1 - 31)
now.getDay() // get weekday as a number (0 - 6)
now.getHours() // get hours (0 - 23)
now.getMinutes() // get minutes (0 - 59)
now.getSeconds() // get seconds (0 - 59)
now.getMilliseconds() // get milliseconds (0 - 999)
now.getTime() // get time (milliseconds since Jan 01, 1970)
Set Methods: Set Date Values for a Date Object:
now.setDate() // set the day as a number (1 - 31)
now.setFullYear() // set the year, (optionally month and day)
now.setHours() // set the hour (0 - 23)
now.setMilliseconds() // set milliseconds
now.setMinutes() // set the minutes (0 - 59)
now.setMonth() // set the month (0 - 11)
now.setSeconds() // set the seconds (0 - 59)
now.setTime() // (milliseconds since Jan 01, 1970)
Methods used on date objects.