Unit 5: Java Date and Time API - Practice Quiz
1 Which Java class represents a date without a time or time zone?
2
Which method adds a specified number of days to a LocalDate?
appendDays()
addDays()
increaseDays()
plusDays()
3
Which method creates a LocalDate from a specific year, month, and day?
LocalDate.build()
LocalDate.make()
LocalDate.create()
LocalDate.of()
4
What does LocalDate.now() return?
5 Which Java class represents a time without a date or time zone?
6
Which method adds minutes to a LocalTime object?
addMinutes()
appendMinutes()
increaseMinutes()
plusMinutes()
7
Which method creates a LocalTime from hour and minute values?
LocalTime.of()
LocalTime.create()
LocalTime.build()
LocalTime.make()
8
What does LocalTime.now() return?
9 Which class combines a date and a time without storing a time zone?
10
Which method combines a LocalDate and a LocalTime into a LocalDateTime?
join()
mergeTime()
atTime()
combine()
11
Which method extracts the date part from a LocalDateTime?
datePart()
getDate()
toLocalDate()
toDate()
12
Which method extracts the time part from a LocalDateTime?
toTimeOnly()
timePart()
getTime()
toLocalTime()
13 Which Java class represents a date and time with a time-zone ID?
14
Which class represents a time-zone identifier such as Europe/Paris?
15
Which method attaches a time zone to a LocalDateTime?
withZone()
atZone()
addZone()
setZone()
16 Which Java class represents a point on the global timeline?
17 Which class is used to represent an amount of date-based time such as years, months, and days?
18 Which class represents a time-based amount such as hours, minutes, and seconds?
19 Which class is used to format and parse Java date and time objects?
20
Which method creates a DateTimeFormatter from a pattern such as dd-MM-yyyy?
DateTimeFormatter.fromPattern()
DateTimeFormatter.ofPattern()
DateTimeFormatter.withPattern()
DateTimeFormatter.createPattern()
21 A conference occurs annually on March 15. Which expression creates the date for the 2026 conference?
22
A subscription starts on 2025-01-31 and must be renewed on the same day of the month whenever possible. What is the result of start.plusMonths(1)?
2025-02-28
2025-02-31
2025-03-01
2025-01-31
23
Which condition correctly checks whether an event date occurs within the inclusive range from startDate through endDate?
event.isBefore(startDate) || event.isAfter(endDate)
!event.isBefore(startDate) && !event.isAfter(endDate)
event.isAfter(startDate) && event.isBefore(endDate)
event.equals(startDate) || event.equals(endDate)
24
A project begins on 2024-02-28 and ends on 2024-03-05. Which value represents the number of elapsed days between the two dates?
8
6
7
5
25
A task starts at 09:45 and lasts 2 hours and 30 minutes. Which expression calculates its ending time?
start.plusHours(2).plusMinutes(30)
start.plusHours(2).minusMinutes(30)
start.plusMinutes(2).plusHours(30)
start.minusHours(2).plusMinutes(30)
26
What is the result of evaluating LocalTime.of(23, 30).plusMinutes(90)?
00:30
23:00
01:00
24:60
27 Which method is most appropriate for checking whether a meeting time is before another meeting time?
first.equals(second)
first.isAfter(second)
first.isBefore(second)
first.compareTo(second) == 1
28 A system records a daily backup at 22:15 and needs to run it every 6 hours. Which object best represents this repeating time interval?
Period.ofDays(6)
LocalDate.of(6, 22, 15)
Duration.ofHours(6)
MonthDay.of(6, 22)
29
Which expression combines the date 2026-04-10 and the time 14:30 into a LocalDateTime?
date.atZone(time)
time.atDate(date).toLocalDate()
LocalDateTime.of(date, time)
LocalDateTime.parse(date + time)
30
A deadline is stored as LocalDateTime deadline. Which expression adds three calendar days while preserving the local time?
deadline.withDayOfMonth(3)
deadline.plusHours(72)
deadline.plusDays(3)
deadline.plus(Period.ofHours(72))
31
Which statement about a LocalDateTime is correct when scheduling an event for users in different regions?
32
What is the result of LocalDateTime.of(2025, 8, 20, 10, 0).toLocalDate()?
2025-08-20
2025-08-20T10:00
10:00
2025-08-21
33
A meeting is scheduled at 09:00 in America/New_York. Which expression creates a zoned date-time for July 1, 2026?
ZonedDateTime.of(LocalDate.of(2026, 7, 1), ZoneId.of("America/New_York"))
ZonedDateTime.of(2026, 7, 1, 9, 0, 0, 0, ZoneId.of("America/New_York"))
LocalDateTime.of(2026, 7, 1, 9, 0).atZone(ZoneId.of("UTC"))
OffsetDateTime.of(2026, 7, 1, 9, 0, ZoneId.of("America/New_York"))
34
A ZonedDateTime represents an event in Tokyo. Which operation converts it to the equivalent local time in London while preserving the same instant?
event.withZoneSameInstant(ZoneId.of("Europe/London"))
event.atZone(ZoneId.of("Europe/London"))
event.toLocalDateTime().atZone(ZoneId.of("Europe/London"))
event.withZoneSameLocal(ZoneId.of("Europe/London"))
35
Why is ZoneId generally preferred over a fixed offset such as +02:00 for recurring events tied to a region?
36 Which object is most appropriate for recording the exact moment when a transaction was received by a server?
Instant
LocalDate
MonthDay
Period
37
What does Duration.between(LocalTime.of(8, 15), LocalTime.of(10, 45)).toMinutes() return?
135
150
180
120
38
Which statement correctly distinguishes Period from Duration?
Period always measures seconds, while Duration measures years.
Period represents an instant, while Duration represents a calendar date.
Period stores a time zone, while Duration stores an offset.
Period uses date units, while Duration uses time-based units.
39
What is the result of adding Period.ofMonths(1) to LocalDate.of(2024, 1, 31)?
2024-02-29
2024-01-31
2024-02-31
2024-03-02
40
Which formatter pattern produces output such as 2026/07/04 09:05 for a LocalDateTime?
yyyy/MM/dd HH:mm
yyyy-mm-dd HH:MM
dd/MM/yyyy hh:mm
MM/dd/yy HH:ss
41
What does the following code print?
LocalDate d = LocalDate.of(2024, 1, 31);
System.out.println(d.plusMonths(1).plusMonths(1) + " | " + d.plusMonths(2));
2024-03-31 | 2024-03-31
2024-04-01 | 2024-03-31
2024-03-29 | 2024-03-31
2024-03-29 | 2024-03-29
42
Given LocalDate date = LocalDate.of(2025, 2, 10);, what is produced by date.with(TemporalAdjusters.lastDayOfMonth()).with(TemporalAdjusters.nextOrSame(DayOfWeek.MONDAY))?
2025-03-10
2025-03-03
2025-02-24
2025-02-28
43
A yearly event is represented by MonthDay.of(2, 29). What does event.atYear(2023) return?
2023-03-01
2023-02-28
2023-02-29
DateTimeException
44
What is the result of ChronoUnit.MONTHS.between(LocalDate.of(2024, 1, 31), LocalDate.of(2024, 3, 30))?
0
2
1
3
45
What does Duration.between(LocalTime.of(23, 30), LocalTime.of(0, 15)) produce?
PT-23H-15M
PT45M
PT-45M
PT23H15M
46
Given LocalTime t = LocalTime.of(12, 34, 56, 987_654_321);, which expression evaluates to 12:34:56.987?
t.truncatedTo(ChronoUnit.MICROS)
t.truncatedTo(ChronoUnit.MILLIS)
t.truncatedTo(ChronoUnit.SECONDS).plusNanos(987_654_321)
t.withNano(987_000_000).plusNanos(654_321)
47
What is the result of the following expression?
LocalDateTime.of(LocalDate.of(2024, 12, 31), LocalTime.MAX).plusNanos(1)
2025-01-01T00:00
2024-12-31T23:59:59.999999999
2025-01-01T00:00:00.000000001
DateTimeException
48
In Europe/Berlin, the local time 2024-03-31T02:30 lies inside a daylight-saving gap. What does LocalDateTime.of(2024, 3, 31, 2, 30).atZone(ZoneId.of("Europe/Berlin")) produce?
DateTimeException
2024-03-31T01:30+01:00[Europe/Berlin]
2024-03-31T02:30+01:00[Europe/Berlin]
2024-03-31T03:30+02:00[Europe/Berlin]
49
Which statement about LocalDateTime is correct when modeling a globally unique scheduled execution?
50
Consider the two occurrences of 2024-11-03T01:30 in America/New_York during the DST overlap. If earlier uses the earlier offset and later uses the later offset, what is Duration.between(earlier, later)?
PT-1H
PT0S
PT2H
PT1H
51
Let z be 2024-01-15T10:00+09:00[Asia/Tokyo]. Which operation creates a Paris value representing the same instant?
z.toLocalDateTime().atZone(ZoneId.of("Europe/Paris"))
z.withFixedOffsetZone().withZoneSameLocal(ZoneId.of("Europe/Paris"))
z.withZoneSameInstant(ZoneId.of("Europe/Paris"))
z.withZoneSameLocal(ZoneId.of("Europe/Paris"))
52
Given
OffsetDateTime a = OffsetDateTime.parse("2024-01-01T10:00+02:00");
OffsetDateTime b = OffsetDateTime.parse("2024-01-01T08:00Z");
which statement is true?
a.equals(b) and a.isEqual(b) are both false
a.equals(b) and a.isEqual(b) are both true
a.equals(b) is true and a.isEqual(b) is false
a.equals(b) is false and a.isEqual(b) is true
53
A fixed clock is created as follows:
Clock c = Clock.fixed(Instant.parse("2024-01-01T00:30:00Z"), ZoneOffset.UTC);
Which pair is returned by LocalDate.now(c.withZone(ZoneId.of("America/Los_Angeles"))) and LocalDate.now(c.withZone(ZoneId.of("Asia/Tokyo"))), respectively?
2024-01-01 and 2024-01-01
2024-01-01 and 2024-01-02
2023-12-31 and 2024-01-02
2023-12-31 and 2024-01-01
54
In America/New_York, let start be 2024-03-09T12:00-05:00. Which result correctly compares start.plus(Period.ofDays(1)) with start.plus(Duration.ofDays(1))?
2024-03-10T12:00-04:00
2024-03-10T13:00-04:00
55
What does Instant.ofEpochSecond(1, 1_500_000_000) return?
1970-01-01T00:00:01.500Z
DateTimeException
1970-01-01T00:00:02.000Z
1970-01-01T00:00:02.500Z
56
What is the result of Period.of(1, 15, 40).normalized()?
P2Y3M40D
P2Y4M10D
P3Y3M10D
P1Y15M40D
57
What happens when Duration.between(LocalDate.of(2024, 1, 1), LocalDate.of(2024, 1, 2)) is evaluated?
P1D
UnsupportedTemporalTypeException
PT0S
PT24H
58
Two ZonedDateTime values in America/New_York represent noon on March 9 and noon on March 10, 2024. What are the results of ChronoUnit.DAYS.between(start, end) and Duration.between(start, end).toHours()?
1 day and 24 hours
0 days and 23 hours
0 days and 24 hours
1 day and 23 hours
59
What happens when the following code is executed?
DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-dd").withResolverStyle(ResolverStyle.STRICT);
LocalDate.parse("2024-02-29", f);
DateTimeParseException
2024-03-01
2024-02-28
2024-02-29
60
A formatter is defined by DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm XXX VV"). What does it produce for ZonedDateTime.of(2024, 7, 1, 9, 5, 0, 0, ZoneId.of("Asia/Kolkata"))?
2024-07-01 03:35 Z Asia/Kolkata
2024-07-01 09:05 +05:30 Asia/Kolkata
2024-07-01 09:05 +0530 Asia/Kolkata
2024-07-01 09:05 IST Asia/Kolkata
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →