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
Use the time object to measure the time of a process
let start = Date.now(); ANY CODE return Date.now() - start;
what do millliseconds in the date object creation argument do?
let date1 = new Date(0); alert(date1 );
let date1 = new Date(123434534); alert(date1 );
Return a date object in milliseconds since Jan01_1970
let date2 = new Date(24 * 3600 * 1000);
alert( date2 );
Date object Jan02_1970 (24 hours per day, 3600 seconds per hour, 1000 milliseconds per second)
What is the order of day month year in a string argument for a date object?
“year-month-day”
Input year, month, day, hour etc as numbers into a date object.
new Date(2011, 0, 1, 0, 0, 0, 0);
What numbers correspond to what month to date objects?
The month count starts with 0 (Jan), up to 11 (Dec)
If the date (day of the month) parameter is absent, what is it assumed to be?
1