Module 3 of 5 · Text
Assigning values
now(ZoneId) → quando quer hora de outro país
now(ZoneId) → when you want the time of another country
.now()
Gets the current date or time from the system.
.of()
Creates a date/time by passing numbers.
.parse()
Converts a String into a date/time object
✅ .now() → when you need the current moment
You use it when the system needs to know:
-
today’s date
-
the current time
-
the exact moment of a purchase
-
whether something is overdue
Real examples:
LocalDate today = LocalDate.now();
LocalDateTime purchaseMoment = LocalDateTime.now();
📌 Commonly used in:
-
payment systems
-
due date verification
-
logging systems
✅ .of() → when you already know the values
You use it when:
-
you are creating a fixed date
-
you are testing your code
-
you are defining a specific rule
LocalDate dueDate = LocalDate.of(2026, 5, 15);
📌 Commonly used in:
-
unit tests
-
system-defined dates
-
calculated or predefined dates
✅ .parse() → when the date comes as TEXT
You use it when:
-
you receive a date from the user
-
you receive a date from a database
-
you receive a date from an API
-
you read a date from a file
Example:
LocalDate date = LocalDate.parse("2026-05-15");
📌 Commonly used in:
-
forms
-
system integration
-
JSON data processing