Selenium + Java · Lesson 13 of 44
Module 13: Java Date & Time
Your task
Implement DateUtil:
Write it in the editor, then press Check answer (Ctrl + Enter).
java.time for Test Engineersimport java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"));
String uniqueEmail = "test_user_" + timestamp + "@targetqa.com";
LocalDate checkInDate = LocalDate.now().plusDays(7);
String formattedCheckIn = checkInDate.format(DateTimeFormatter.ofPattern("MM/dd/yyyy"));Every test suite deals with timestamps: generating unique user emails, picking flight reservation dates, and verifying invoices. In this lesson, we use java.time to format dates and calculate future test dates. Let's master Date and Time!
Part of the Selenium + Java course (Selenium with Java). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.
SimpleDateFormat is not thread-safe and causes race conditions in parallel test runs. java.time classes are immutable and thread-safe.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___