Dates Flashcards
Return today’s date and time in ms since 1970
Date.now()
or from a date object
Date.prototype.getTime()
Return any date and time in ms since 1970
Date.parse(‘2021, oct 11’)
or
new Date(‘2021, oct 11’).getTime()
Return a date object with today’s date/time OR any date/time
For now:
new Date()
For any date:
new Date(‘December 25, 2012’)
Return a date object with today’s date
new Date()
Return today’s date/time/etc as a string
Date()
Return a number representing the year minus 1900
Get date object
Do getyear method
Date.prototype.getYear()
Return the year as a number
Date.prototype.getFullYear()
Return the day of the week as a number Sunday=0 Monday= 1 ... Saturday = 6
Date.prototype.getDate()
Create a function that returns the day of the week from an given date
Return the date of the week as a string: Get day of week: > let date = new Date('December 25, 2012') > date.getDay() = 2 // a tuesday
let dayOfWeek = [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
Use these numbers as indices on an array with words for the days of the week.
What is returned from each of these
Date()
Date.now()
Date.parse(‘2021, oct 11’)
new Date() new Date('December 25, 2012')
new Date().getYear() new Date().getFullYear() new Date().getDate()
Date() - A string with date, time, and time zone info for right now:
Mon Jan 17 2022 20:32:57 GMT-0500 (Eastern Standard Time)
Date.now() - date and time in ms fromJanuary 1, 1970 till right now
Date.parse(‘2021, oct 11’) - date and time in ms fromJanuary 1, 1970 till the entered time
new Date() - creates a date object (purple text) of the date and time right now 2022-01-18T01:35:26.880Z new Date('December 25, 2012') - creates a date object (purple text) of the date and time of the given date
new Date().getYear() - from a date object, return the year as a number minus 1900 new Date().getFullYear() - from a date object, return the year as a number (in years since year 0) new Date().getDate() - from a date object, return the day of the month as a number. Returns NaN when the day is 0 or greater than the number of days the month should have new Date().getDay() - from a date object, return the day of the week as a number.
What does
Date()
do?
Date() - A string with date, time, and time zone info for right now:
Mon Jan 17 2022 20:32:57 GMT-0500 (Eastern Standard Time)
What does
Date.now()
do or return?
Date.now() - returns date and time in ms fromJanuary 1, 1970 till right now
What does
Date.parse(‘2021, oct 11’)
do?
Date.parse(‘2021, oct 11’) - date and time in ms fromJanuary 1, 1970 till the entered time
What does new Date() do?
new Date() - creates a date object (purple text) of the date and time (date seems to be wrong) right now 2022-01-18T01:35:26.880Z
What does new Date('December 25, 2012') do?
new Date(‘December 25, 2012’) - creates a date object (purple text) of the date and time (date seems to be wrong) of the given date
What does new Date().getYear() do?
Date.prototype.getYear() - from a date object, return the year as a number minus 1900
Don’t use it, it’s old and silly
What does new Date().getFullYear() do?
Date.prototype.getFullYear() - from a date object, return the year as a number (in years since year 0)
What does new Date().getDate() do?
Date.prototype.getDate() - from a date object, return the day of the month as a number. Returns NaN when the day is 0 or greater than the number of days the month should have