This project focuses on date manipulation within the Java Time API. It demonstrates how to perform basic date arithmetic by moving the current system date one step into the past. This functionality is a core requirement for applications dealing with historical records, logs, or daily reports.
- Current Date: Successfully retrieves today's date using
LocalDate.now(). - Date Arithmetic: Uses the
minusDays(1)method to calculate the date of the previous day. - Variable Declaration: Implements variables
todayandyesterdayof typeLocalDate. - Output: Displays the calculated yesterday's date in the console.
- Goal: Master relative date navigation in Java.
- Java 8+ (java.time.LocalDate)
The LocalDate class is immutable, meaning methods like minusDays() do not change the existing object but return a new LocalDate instance representing the result. This ensures data integrity across the application.
Yesterday was: 2026-03-03
Project Structure:
src/com/yurii/pavlenko/
└── Solution.java
Code
package com.yurii.pavlenko;
import java.time.LocalDate;
public class Solution {
public static void main(String[] args) {
LocalDate today = LocalDate.now();
LocalDate yesterday = today.minusDays(1);
System.out.println("Yesterday was: " + yesterday);
}
}This project is licensed under the MIT License.
Copyright (c) 2026 Yurii Pavlenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...
License: MIT