JavaScript Date and Time Manipulation Quiz

Create an account and save your quiz results

Login and save your results

OR

Question 1/15

Which method would you use to retrieve the full year (such as 2023) from a JavaScript `Date` object?
let date = new Date('2023-10-08');

Select your answer

Question 2/15

If you have a `Date` object and you want to format it to 'YYYY-MM-DD' format, which method would you use in combination with manual string construction?
let date = new Date('2023-10-08');

Select your answer

Question 3/15

What does the `getUTCHours()` method do for a `Date` object?
let date = new Date();

Select your answer

Question 4/15

How would you set the minutes of a `Date` object to 45?
let date = new Date();

Select your answer

Question 5/15

How can the `Date.UTC()` method be used in JavaScript?

Select your answer

Question 6/15

What does the `toISOString` method do when called on a JavaScript `Date` object?
let date = new Date('2023-10-08T12:00:00');

Select your answer

Question 7/15

Which JavaScript object provides methods for internationalization and localization of date and time?

Select your answer

Question 8/15

Which method would you use to get the current minutes from a `Date` object?
let date = new Date();

Select your answer

Question 9/15

Which method can you use to convert a `Date` object to a string with only the time part, in the local time zone?
let date = new Date();

Select your answer

Question 10/15

What is the purpose of the JavaScript `Date` object?

Select your answer

Question 11/15

How do you get the month index from a JavaScript `Date` object (e.g., January is 0)?
let date = new Date('2023-10-08');

Select your answer

Question 12/15

How can you set the year of a JavaScript `Date` object to 2025?
let date = new Date();

Select your answer

Question 13/15

How can you get the last day of a particular month using JavaScript `Date`? (e.g., how to get the last day of February 2023)
let year = 2023;
let month = 1; // February
let date = new Date(year, month + 1, 0);

Select your answer

Question 14/15

How do you get the number of milliseconds since January 1, 1970, for a specific date object in JavaScript?
let date = new Date('2023-01-01');

Select your answer

Question 15/15

What is a valid reason to use `Date.parse()` in JavaScript?

Select your answer

Your Results

You did not answer any questions correctly.

Your Answers

Question 1/15
😊 Your answer was correct 🙁 Your answer was incorrect
Which method would you use to retrieve the full year (such as 2023) from a JavaScript `Date` object?
let date = new Date('2023-10-08');

Available answers

The `getFullYear()` method retrieves the 4-digit year from a Date object.
Question 2/15
😊 Your answer was correct 🙁 Your answer was incorrect
If you have a `Date` object and you want to format it to 'YYYY-MM-DD' format, which method would you use in combination with manual string construction?
let date = new Date('2023-10-08');

Available answers

For manual formatting, use `date.getFullYear()`, `date.getMonth()`, adjusting month to `+1` for 1-indexing, and `date.getDate()`. Combine these in a formatted string like `YYYY-MM-DD`.
Question 3/15
😊 Your answer was correct 🙁 Your answer was incorrect
What does the `getUTCHours()` method do for a `Date` object?
let date = new Date();

Available answers

The `getUTCHours()` method returns the hours (0-23) of a Date object, according to universal time.
Question 4/15
😊 Your answer was correct 🙁 Your answer was incorrect
How would you set the minutes of a `Date` object to 45?
let date = new Date();

Available answers

To set the minutes of a Date object to 45, you use `date.setMinutes(45)`. This method updates the minutes of the Date object.
Question 5/15
😊 Your answer was correct 🙁 Your answer was incorrect
How can the `Date.UTC()` method be used in JavaScript?

Available answers

The `Date.UTC()` method accepts date components and returns the number of milliseconds since January 1, 1970, UTC. It doesn't create a Date object but gives a timestamp.
Question 6/15
😊 Your answer was correct 🙁 Your answer was incorrect
What does the `toISOString` method do when called on a JavaScript `Date` object?
let date = new Date('2023-10-08T12:00:00');

Available answers

The `toISOString()` method returns a string in simplified extended ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ), which is a widely-used format for date/time representations.
Question 7/15
😊 Your answer was correct 🙁 Your answer was incorrect
Which JavaScript object provides methods for internationalization and localization of date and time?

Available answers

The `Intl.DateTimeFormat` object is part of the ECMAScript Internationalization API and provides language-sensitive date and time formatting.
Question 8/15
😊 Your answer was correct 🙁 Your answer was incorrect
Which method would you use to get the current minutes from a `Date` object?
let date = new Date();

Available answers

The `getMinutes()` method returns the minutes of a date as a number (0 to 59).
Question 9/15
😊 Your answer was correct 🙁 Your answer was incorrect
Which method can you use to convert a `Date` object to a string with only the time part, in the local time zone?
let date = new Date();

Available answers

The `toLocaleTimeString()` method converts the time portion of a Date object to a string, using the current locale's formatting conventions.
Question 10/15
😊 Your answer was correct 🙁 Your answer was incorrect
What is the purpose of the JavaScript `Date` object?

Available answers

The JavaScript `Date` object is used for creating, managing, and formatting dates and times. It provides methods for getting and setting the year, month, day, hour, minute, second, and millisecond individually.
Question 11/15
😊 Your answer was correct 🙁 Your answer was incorrect
How do you get the month index from a JavaScript `Date` object (e.g., January is 0)?
let date = new Date('2023-10-08');

Available answers

The `getMonth()` method returns the month index of a Date object, where January is 0, February is 1, and so on.
Question 12/15
😊 Your answer was correct 🙁 Your answer was incorrect
How can you set the year of a JavaScript `Date` object to 2025?
let date = new Date();

Available answers

To set the year of a `Date` object, use the `setFullYear()` method. For example, `date.setFullYear(2025)` will set the year to 2025.
Question 13/15
😊 Your answer was correct 🙁 Your answer was incorrect
How can you get the last day of a particular month using JavaScript `Date`? (e.g., how to get the last day of February 2023)
let year = 2023;
let month = 1; // February
let date = new Date(year, month + 1, 0);

Available answers

Setting the day to 0 of the next month gives the last day of the preceding month. Here, `new Date(year, month + 1, 0)` results in the last day of February.
Question 14/15
😊 Your answer was correct 🙁 Your answer was incorrect
How do you get the number of milliseconds since January 1, 1970, for a specific date object in JavaScript?
let date = new Date('2023-01-01');

Available answers

The `getTime()` method returns the number of milliseconds since January 1, 1970, 00:00:00 UTC for the specified date object.
Question 15/15
😊 Your answer was correct 🙁 Your answer was incorrect
What is a valid reason to use `Date.parse()` in JavaScript?

Available answers

`Date.parse()` is used to parse a date string and return the number of milliseconds between the date represented by the string and midnight of January 1, 1970.