Courseiva

1Z0-829 Practice Question: Handling Date, Time, Text, Numeric and Boolean Values

Which of the following correctly formats a LocalDateTime object into a string with pattern 'dd/MM/yyyy HH:mm:ss'?

⚠ Common exam trap

A common mix-up: candidates confuse the legacy `SimpleDateFormat` (which works with `java.util.Date`) with the modern `DateTimeFormatter` (which works with `java.time.LocalDateTime`), or assume `String.format` can directly format `LocalDateTime` without realizing it requires a `Date` object.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss").format(dateTime)

`DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss")` creates a formatter with the specified pattern, and calling `.format(dateTime)` on that formatter converts a `LocalDateTime` object to a string in the exact requested format. This is the standard approach in Java 8+ using the `java.time` API, which is thread-safe and immutable.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss").format(dateTime)

    Why this is correct

    Correct: DateTimeFormatter.ofPattern creates a formatter for the custom pattern, and format works with LocalDateTime.

  • String.format("%1$td/%1$tm/%1$tY %1$tH:%1$tM:%1$tS", dateTime)

    Why it's wrong here

    Incorrect: String.format expects a Date or Temporal, not LocalDateTime directly, and may throw exceptions.

  • new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(dateTime)

    Why it's wrong here

    Incorrect: SimpleDateFormat expects java.util.Date, not LocalDateTime.

  • dateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)

    Why it's wrong here

    Incorrect: ISO_LOCAL_DATE_TIME produces a different format like '2024-07-04T10:30:00'.

About these practice questions

Courseiva writes every 1Z0-829 question from scratch — 513 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.