1Z0-829 · Question #32
Given the code fragment: Duration duration = Duration.ofMillis(5000); System.out.println(duration); duration = Duration.ofSeconds(60); System.out.println(duration); Period period = Period.ofDays(6)…
The correct answer is B. PT5000PT60MP6D. Option B is correct because Java's Duration.toString() uses ISO-8601 format with the PT prefix (Period of Time), so Duration.ofMillis(5000) outputs PT5S (5000ms normalizes to 5 seconds) and Duration.ofSeconds(60) outputs PT60S - Duration does not automatically convert 60…
Question
Options
- A$$SIM6D
- BPT5000PT60MP6D
- CPT5S0MP6D
- DS000S60M6D
How the community answered
(28 responses)- A7% (2)
- B71% (20)
- C18% (5)
- D4% (1)
Explanation
Option B is correct because Java's Duration.toString() uses ISO-8601 format with the PT prefix (Period of Time), so Duration.ofMillis(5000) outputs PT5S (5000ms normalizes to 5 seconds) and Duration.ofSeconds(60) outputs PT60S - Duration does not automatically convert 60 seconds to PT1M; it retains the unit as given. Period.toString() uses the P prefix (without T) for date-based values, so Period.ofDays(6) outputs P6D.
Option A ($$SIM6D) is nonsensical - no Java date/time class produces $ or SIM tokens. Option C (PT5S0MP6D) incorrectly merges the two Duration outputs into a single garbled string and loses the PT60S line. Option D (S000S60M6D) omits the required P/PT ISO-8601 prefixes entirely.
Memory tip: Think PT = Period of Time (for Duration, which measures time) and P alone = Period (for Period, which measures dates). The T in PT is your signal that seconds/minutes/hours are involved.
Topics
Community Discussion
No community discussion yet for this question.