let date = new Date('2023-01-01');
JavaScript Date and Time Manipulation Quiz
Want to learn more than this quiz offers you? Have a look at my Frontend web
development courses.
Create an account and save your quiz results
Login and save your results
OR
Question 1/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 2/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 3/15
What is the method for setting the day of the month for a `Date` object in JavaScript?
let date = new Date();
Select your answer
Question 4/15
Which method would you use to get the current minutes from a `Date` object?
let date = new Date();
Select your answer
Question 5/15
How do you create a new `Date` object representing the current date and time in JavaScript?
Select your answer
Question 6/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 7/15
How would you set the minutes of a `Date` object to 45?
let date = new Date();
Select your answer
Question 8/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 9/15
How can you add one hour to a `Date` object in JavaScript?
let date = new Date();
Select your answer
Question 10/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 11/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 12/15
What is the purpose of the JavaScript `Date` object?
Select your answer
Question 13/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 14/15
If you need to manipulate time in JavaScript using libraries, which library is the most popular choice?
Select your answer
Question 15/15
How do JavaScript `Date` objects internally store date values?
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 do you get the number of milliseconds since January 1, 1970, for a specific date object in JavaScript?
Available answers
The `getTime()` method returns the number of milliseconds since January 1, 1970, 00:00:00 UTC for the specified date object.
Question 2/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 3/15
😊 Your
answer was correct
🙁 Your
answer was incorrect
What is the method for setting the day of the month for a `Date` object in JavaScript?
let date = new Date();
Available answers
The `setDate()` method sets the day of the month for a date, taking a number from 1 to 31.
Question 4/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 5/15
😊 Your
answer was correct
🙁 Your
answer was incorrect
How do you create a new `Date` object representing the current date and time in JavaScript?
Available answers
In JavaScript, you create a new Date object representing the current date and time by using `new Date()`. This uses the system's current time and date.
Question 6/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 7/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 8/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 9/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 10/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 11/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 12/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 13/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 14/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 15/15
😊 Your
answer was correct
🙁 Your
answer was incorrect
How do JavaScript `Date` objects internally store date values?
Available answers
Internally, JavaScript `Date` objects store dates as the number of milliseconds since midnight of January 1, 1970 UTC.