JavaScript Date and Time Manipulation Quiz

Create an account and save your quiz results

Login and save your results

OR

Question 1/15

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

Select your answer

Question 2/15

How can you add one hour to a `Date` object in JavaScript?
let date = new Date();

Select your answer

Question 3/15

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

Select your answer

Question 4/15

Which method would you use to convert a JavaScript `Date` object to a string in the format: Wed Oct 08 2023?
let date = new Date('2023-10-08');

Select your answer

Question 5/15

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

Select your answer

Question 6/15

Which of the following will return the day of the week from a JavaScript `Date` object?
let date = new Date('2023-10-08');

Select your answer

Question 7/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 8/15

Which method would you use to get the UTC date of a `Date` object in JavaScript?
let date = new Date();

Select your answer

Question 9/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 10/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 11/15

If you need to manipulate time in JavaScript using libraries, which library is the most popular choice?

Select your answer

Question 12/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 13/15

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

Select your answer

Question 14/15

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

Select your answer

Question 15/15

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

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
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 2/15
😊 Your answer was correct 🙁 Your answer was incorrect
How can you add one hour to a `Date` object in JavaScript?
let date = new Date();

Available answers

To add one hour to a `Date` object, use the `setHours` method with the `getHours` method, like this: `date.setHours(date.getHours() + 1)`. This increments the hour by 1.
Question 3/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 4/15
😊 Your answer was correct 🙁 Your answer was incorrect
Which method would you use to convert a JavaScript `Date` object to a string in the format: Wed Oct 08 2023?
let date = new Date('2023-10-08');

Available answers

The `toDateString()` method returns the date portion of a Date object as a string in a human-readable format like `Wed Oct 08 2023`.
Question 5/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 6/15
😊 Your answer was correct 🙁 Your answer was incorrect
Which of the following will return the day of the week from a JavaScript `Date` object?
let date = new Date('2023-10-08');

Available answers

The method `getDay()` on a Date object returns the day of the week as a number, where Sunday is 0, Monday is 1, and so on.
Question 7/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 8/15
😊 Your answer was correct 🙁 Your answer was incorrect
Which method would you use to get the UTC date of a `Date` object in JavaScript?
let date = new Date();

Available answers

The `getUTCDate()` method returns the day of the month as a number (1-31) according to universal time (UTC).
Question 9/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 10/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 11/15
😊 Your answer was correct 🙁 Your answer was incorrect
If you need to manipulate time in JavaScript using libraries, which library is the most popular choice?

Available answers

While many alternatives exist, `moment.js` has historically been one of the most popular libraries for date manipulation in JavaScript. However, it is in maintenance mode, and newer libraries like `date-fns` or `Luxon` are now recommended.
Question 12/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 13/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 14/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 15/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.