Of course! The term "Java Calendar day" can refer to a few different things, but it most commonly relates to how to get, set, and manipulate the day of the month using Java's Calendar class.

Let's break it down, starting with the older Calendar class and then moving to the modern, recommended java.time package.
Using the Legacy java.util.Calendar Class
Before Java 8, java.util.Calendar was the primary way to handle dates and times. It's powerful but can be a bit verbose and error-prone.
Key Concepts for "Day"
Calendar.DAY_OF_MONTH: This is the constant you use to refer to the day of the month (e.g., 1 through 31). This is what most people mean by "day" in a calendar context.Calendar.DAY_OF_WEEK: This constant refers to the day of the week (e.g.,Calendar.SUNDAY,Calendar.MONDAY, etc.). It's a different concept.
How to Get the Day of the Month
You use the get() method and pass it the Calendar.DAY_OF_MONTH constant.
import java.util.Calendar;
public class CalendarDayExample {
public static void main(String[] args) {
// Get the current date and time
Calendar calendar = Calendar.getInstance();
// Get the day of the month
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println("Today's day of the month is: " + dayOfMonth);
// Example Output: Today's day of the month is: 26
}
}
How to Set the Day of the Month
You use the set() method. This is useful for creating specific dates.

import java.util.Calendar;
public class CalendarSetDayExample {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
// Set the date to December 25th, 2025
calendar.set(Calendar.YEAR, 2025);
calendar.set(Calendar.MONTH, Calendar.DECEMBER); // Note: Months are 0-indexed (0=Jan, 11=Dec)
calendar.set(Calendar.DAY_OF_MONTH, 25);
int day = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println("The set date is: " + calendar.getTime());
System.out.println("Day of the month for that date: " + day);
// Example Output:
// The set date is: Wed Dec 25 10:30:00 CST 2025
// Day of the month for that date: 25
}
}
How to Add or Subtract Days
Use the add() method to modify the date. This is very useful for calculations like "what is the date 10 days from now?".
import java.util.Calendar;
public class CalendarAddDaysExample {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
System.out.println("Today is: " + calendar.getTime());
// Add 10 days to the current date
calendar.add(Calendar.DAY_OF_MONTH, 10);
System.out.println("Date after adding 10 days: " + calendar.getTime());
// Subtract 5 days from the current date
calendar.add(Calendar.DAY_OF_MONTH, -5);
System.out.println("Date after subtracting 5 days: " + calendar.getTime());
}
}
The Modern Approach: java.time Package (Java 8 and later)
Since Java 8, the java.time package is the official and highly recommended way to handle dates and times. It's more intuitive, immutable (safer from bugs), and easier to read.
The main classes for dates are:
LocalDate: Represents a date (year, month, day) without a time.LocalDateTime: Represents a date and time.ZonedDateTime: Represents a date and time with a time zone.
How to Get the Day of the Month with LocalDate
The method is simply getDayOfMonth().

import java.time.LocalDate;
public class LocalDateDayExample {
public static void main(String[] args) {
// Get the current date
LocalDate today = LocalDate.now();
// Get the day of the month
int dayOfMonth = today.getDayOfMonth();
System.out.println("Today's day of the month is: " + dayOfMonth);
// Example Output: Today's day of the month is: 26
}
}
How to Set the Day of the Month with LocalDate
Since LocalDate objects are immutable, you don't "set" them. Instead, you create a new object using the withDayOfMonth() method.
import java.time.LocalDate;
public class LocalDateWithDayExample {
public static void main(String[] args) {
// Create a specific date: December 25th, 2025
LocalDate christmas = LocalDate.of(2025, 12, 25);
System.out.println("Christmas is on: " + christmas);
// Create a new date by changing the day of the month
LocalDate lastDayOfMonth = christmas.withDayOfMonth(31);
System.out.println("The last day of that month is: " + lastDayOfMonth);
}
}
How to Add or Subtract Days with LocalDate
Use the plusDays() and minusDays() methods. These also return new LocalDate objects.
import java.time.LocalDate;
public class LocalDatePlusMinusExample {
public static void main(String[] args) {
LocalDate today = LocalDate.now();
System.out.println("Today is: " + today);
// Add 10 days to the current date
LocalDate futureDate = today.plusDays(10);
System.out.println("Date after adding 10 days: " + futureDate);
// Subtract 5 days from the current date
LocalDate pastDate = today.minusDays(5);
System.out.println("Date after subtracting 5 days: " + pastDate);
}
}
Summary: Calendar vs. java.time
| Feature | java.util.Calendar (Legacy) |
java.time.LocalDate (Modern) |
|---|---|---|
| Immutability | Mutable. Can be changed after creation. | Immutable. Methods return new objects. |
| Clarity | Verbose. Uses constants like Calendar.DAY_OF_MONTH. |
Clear. Uses method names like getDayOfMonth(). |
| Month Index | 0-indexed (0=January, 11=December). A common source of bugs. | 1-indexed. More intuitive. |
| Thread Safety | Not thread-safe. | Thread-safe (because it's immutable). |
| Recommendation | Avoid for new code. Only for maintaining old projects. | Use for all new Java 8+ code. |
Quick Reference Table
| Task | java.util.Calendar |
java.time.LocalDate |
|---|---|---|
| Get current day | calendar.get(Calendar.DAY_OF_MONTH) |
LocalDate.now().getDayOfMonth() |
| Set a specific day | calendar.set(Calendar.DAY_OF_MONTH, 15) |
LocalDate.of(2025, 5, 15) |
| Add days | calendar.add(Calendar.DAY_OF_MONTH, 7) |
date.plusDays(7) |
| Subtract days | calendar.add(Calendar.DAY_OF_MONTH, -3) |
date.minusDays(3) |
| Get day of week | calendar.get(Calendar.DAY_OF_WEEK) |
date.getDayOfWeek() (returns an enum) |
Conclusion: For any new development, you should strongly prefer using the java.time package. It is the modern standard and makes date manipulation much cleaner and safer. Use the Calendar class only if you are working with legacy codebases that rely on it.
