Last Updated: December 6, 2025
31 quizzes
Create a LocalDate for 2023-10-01 to represent a due date in a task manager
LocalDate dueDate = LocalDate.(2023, 10, 1);Click an option to fill the blank:
Measure how many days are between two LocalDate values for a subscription period
long days = ChronoUnit. .between(startDate, endDate);Click an option to fill the blank:
Format a LocalDateTime using a reusable formatter before logging it
String text = dateTime.format(DateTimeFormatter. );Click an option to fill the blank:
Which statement about the Java 8 Date & Time API classes like LocalDate and LocalTime is TRUE?
What does LocalDate represent in the Java Date & Time API?
Which method gets the current LocalTime using the system clock?
Which class should you use to represent a moment on the UTC timeline for logging events?
You need to schedule a meeting for "2025-03-10T09:00" in Europe/Berlin. Which class best represents this?
Which type is best for representing a 3-day vacation length, independent of start date?
Which DateTimeFormatter is predefined for a standard ISO local date like 2025-01-31?
How do DateTimeFormatter patterns treat 'MM' and 'mm'?
What does ChronoUnit.DAYS.between(start, end) return when used with two LocalDate values?
Which approach converts a LocalDateTime to a specific time zone-aware value?
Which statement about Duration and Period is TRUE?
Order the steps to create a ZonedDateTime from the current local date-time in a specific zone and then format it for display.
Drag and drop to reorder, or use the arrows.
Order the steps to measure a task's running time using Instant and Duration.
Drag and drop to reorder, or use the arrows.
What is the output of this code that calculates days between two dates?
1import java.time.*;
2import java.time.temporal.ChronoUnit;
3
4public class Main {
5 public static void main(String[] args) {
6 LocalDate start = LocalDate.of(2024, 1, 1);
7 LocalDate end = LocalDate.of(2024, 1, 10);
8 long days = ChronoUnit.DAYS.between(start, end);
9 System.out.println(days);
10 }
11}What does this code print when adding a Period to a LocalDate?
1import java.time.*;
2
3public class Main {
4 public static void main(String[] args) {
5 LocalDate date = LocalDate.of(2023, 12, 31);
6 Period period = Period.ofDays(1);
7 LocalDate result = date.plus(period);
8 System.out.println(result);
9 }
10}What is the output when formatting a LocalTime?
1import java.time.*;
2import java.time.format.*;
3
4public class Main {
5 public static void main(String[] args) {
6 LocalTime time = LocalTime.of(9, 5);
7 DateTimeFormatter f = DateTimeFormatter.ofPattern("HH:mm");
8 System.out.println(time.format(f));
9 }
10}What does this code print when converting a LocalDateTime to an Instant in UTC?
1import java.time.*;
2
3public class Main {
4 public static void main(String[] args) {
5 LocalDateTime ldt = LocalDateTime.of(2020, 1, 1, 0, 0);
6 ZonedDateTime zdt = ldt.atZone(ZoneId.of("UTC"));
7 Instant instant = zdt.toInstant();
8 System.out.println(instant);
9 }
10}What is printed when computing a Duration in minutes between two times?
1import java.time.*;
2
3public class Main {
4 public static void main(String[] args) {
5 LocalTime start = LocalTime.of(10, 0);
6 LocalTime end = LocalTime.of(11, 30);
7 long minutes = Duration.between(start, end).toMinutes();
8 System.out.println(minutes);
9 }
10}Find the bug in this code that parses a date string and prints it.
Click on the line(s) that contain the bug.
import java.time.*;import java.time.format.*; public class Main { public static void main(String[] args) { String text = "31-01-2024"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDate date = LocalDate.parse(text, formatter); System.out.println(date); }}Find the bug in this code that tries to create a Duration between two LocalDate values.
Click on the line(s) that contain the bug.
import java.time.*; public class Main { public static void main(String[] args) { LocalDate start = LocalDate.of(2024, 1, 1); LocalDate end = LocalDate.of(2024, 1, 5); Duration d = Duration.between(start, end); System.out.println(d.toDays()); }}Match each date-time class with its most appropriate description.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match the Date & Time API concepts with their typical use cases.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code to create a LocalDateTime from separate LocalDate and LocalTime objects and format it using a custom pattern.
import java.time.*;import java.time.format.*;public class Main { public static void main(String[] args) { LocalDate date = LocalDate.of(2024, 5, 10); LocalTime time = LocalTime.of(14, 30); LocalDateTime dateTime = .of(date, time); DateTimeFormatter formatter = DateTimeFormatter.("yyyy/MM/dd HH:mm"); String text = dateTime.(formatter); System.out.println(text); }}Click an option to fill blank 1:
Complete the code to add a one-week Period to a LocalDate and print the result.
import java.time.*;public class Main { public static void main(String[] args) { LocalDate start = LocalDate.of(2024, 3, 1); Period p = Period.(0, 0, 7); LocalDate result = start.(p); System.out.println(result); }}Click an option to fill blank 1:
Complete the code to obtain the current time in a specific zone and convert it to another zone.
import java.time.*;public class Main { public static void main(String[] args) { ZonedDateTime nyTime = ZonedDateTime.now(ZoneId.of("America/New_York")); ZonedDateTime tokyoTime = nyTime.(ZoneId.of("Asia/Tokyo")); Instant instant = tokyoTime.(); System.out.println(instant); }}Click an option to fill blank 1:
Complete the code to parse a date string with ISO_LOCAL_DATE and then print the next day.
import java.time.*;import java.time.format.*;public class Main { public static void main(String[] args) { String text = "2024-10-01"; LocalDate date = LocalDate.(text, DateTimeFormatter.ISO_LOCAL_DATE); LocalDate nextDay = date.Days(1); System.out.println(nextDay); }}Click an option to fill blank 1:
Click the line that applies the DateTimeFormatter to format the LocalDate.
Click on the line to select.
import java.time.*;import java.time.format.*; public class Main { public static void main(String[] args) { LocalDate today = LocalDate.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); String text = today.format(formatter); System.out.println(text); }}Click the line that converts the current moment into a ZonedDateTime using the system default zone.
Click on the line to select.
import java.time.*; public class Main { public static void main(String[] args) { Instant now = Instant.now(); ZoneId systemZone = ZoneId.systemDefault(); ZonedDateTime zoned = now.atZone(systemZone); System.out.println(zoned); }}