Preview

14 - JavaScript and Date and Time

 1. JavaScript____________lets us work with dates

  date_time_numeric Object

  Number Object

  Time Object

  Date Object

 2. What could this object be used for?
Create a website with a calendar
Create a train schedule
Create an interface to set up appointments
Show relevant times based on the user's current timezone
Perform calculations around arrivals and departures or start and end times
Generate a report at a certain time every day
Filter through currently open restaurants and establishments

  Items 1 and 3 on the list

  Only item 3 and 5 on the list

  Items 1,2,3 on the list

  All items on the list are valid uses of this object

 3. The Date object is __________ object in JavaScript that stores the date and time. It provides a number of built-in methods for formatting and managing that data.

  a single variable

  a fixed

  an external

  a built-in

 4. What are we doing in the first line of this code?
const now = new Date();

// View the output
now;

  setting the current date and time to contain the word 'now'

  setting the current date and time to be a constant (i.e always the same date/time)

  setting the variable to current date and time

  setting the variable to contain a constant which will cause an error

 5. Epoch time was chosen as a standard for computers to measure time by in earlier days of programming, and it is the method that JavaScript uses
Epoch time, also referred to as zero time, is represented by the date string 
01 January, 1970 00:00:00 Universal Time (UTC), and by the 0 timestamp. 

We can test this in the browser by creating a new variable and assigning 
to it a new Date instance based on a timestamp of 0.

  TRUE

  FALSE

 6. What is the output of the following command?
new Date()

  Creates date based on milliseconds since Epoch time

  Current date and time

  Creates date based on date string

  Creates date based on specified date and time

 7. What is the output of the following command?
new Date(timestamp)

  Creates date based on date string

  Creates date based on milliseconds since Epoch time

  Creates date based on specified date and time

  Current date and time

 8. What is the output of the following command?
new Date(year, month, day, hours, minutes, seconds, milliseconds)

  Creates date based on specified date and time

  Current date and time

  Creates date based on date string

  Creates date based on milliseconds since Epoch time

 9. Why is the output here negative?
// Timestamp method
new Date(-6106015800000);

  None of these answers are valid

  Because a capital 'D' has been used in Date which causes it to be negative

  Any date prior to Epoch time will be represented as a negative number.

  Because the key word 'new' has been used

 10. In the date and time method, our seconds and milliseconds are set to __. If any number is missing from the Date creation, it will default to ____

  GMT

  1

  0

  60 (for 60 seconds)

 11. Has this function been set up correctly? Assume the date at the time of writing is March 30. What is the output?
// Get today's date
const today = new Date();

// Compare today with October 3rd
if (today.getDate() === 3 && today.getMonth() === 9) {
  console.log("It's October 3rd.");
} else {
  console.log("It's not October 3rd.");
}

  It's not October 3rd

  It's October 3rd

  Compare today with October 3rd

  Error

 12. The built-in methods beginning with set let us modify different parts of a Date object
// Change year of birthday date
birthday.setFullYear(1997);

birthday;

  TRUE

  FALSE

 13. Date objects are created with the new Date() constructor. There are four ways to create a new date.
new Date()
new Date(year, month, day, hours, minutes, seconds, milliseconds)
new Date(milliseconds)
new Date(date string)

  FALSE

  TRUE

 14. JavaScript counts months from 0 to 11. January is 0. December is 11

  TRUE

  FALSE

 15. Which one of the following date input formats is considered the international standard?
ISO Date	"2015-03-25" (The International Standard)
Short Date	"03/25/2015"
Long Date	"Mar 25 2015" or "25 Mar 2015"

  None of these date input formats are correct

  The third one

  The second one

  The first one