LocalDate PlusDays And EpochDay Math
Advance dates with plusDays and minusDays across month boundaries, then convert with toEpochDay and fromEpochDay when plain day counts are needed.
Code
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
public class DeadlinePlanner {
public static void main(String[] args) {
LocalDate release = LocalDate.of(2026, 11, 30);
// plusDays/minusDays 按日历推进:跨月自动进位,不需要手写天数修正
System.out.println("plus 3 days: " + release.plusDays(3));
System.out.println("minus 35 d: " + release.minusDays(35));
// epochDay:把日期转成自 1970-01-01 的天数,差值就是普通整数运算
long start = LocalDate.of(2026, 11, 1).toEpochDay();
long end = release.toEpochDay();
System.out.println("epoch days between: " + (end - start));
// 反向:fromEpochDay 把天数还原成日期
System.out.println("from epoch day: " + LocalDate.ofEpochDay(start + 7));
// until 同样给出整段跨度:装不下的小单位被截断,不四舍五入
System.out.println("until DAYS: " + ChronoUnit.DAYS.between(LocalDate.of(2026, 11, 1), release));
System.out.println("until WEEKS: " + ChronoUnit.WEEKS.between(LocalDate.of(2026, 11, 1), release));
}
}How it works
Everything happens inside the class DeadlinePlanner and the function main.
What to watch for
- Runs on the standard library alone; nothing to install.
Using it
The primary signature is public static void main(String[] args)
Output lines carry labels — plus 3 days:, minus 35 d:, epoch days between: — when the file runs.
Key statements
long start = LocalDate.of(2026, 11, 1).toEpochDay();
LocalDate release = LocalDate.of(2026, 11, 30);
long end = release.toEpochDay();
Interactive Tools for This Topic
Age CalculatorCalculate exact age in years, months, and days between a birth date and a reference date, plus total days and the next birthday countdown.Business Days CalculatorCount the weekdays between two dates, excluding weekends and any holidays you list, and see how many calendar and weekend days are involved.Cron Next Runs CalculatorCompute the next scheduled run times for a standard five-field cron expression, supporting ranges, lists, steps, and day-of-week naming semantics.GCD & LCM CalculatorFind the greatest common divisor and least common multiple of two or more integers, computed exactly with BigInt.
FAQ
- What does LocalDate PlusDays And EpochDay Math print when run?
- The script runs standalone; its 6 labeled outputs include `plus 3 days:`, `minus 35 d:`, `epoch days between:`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.