Java Add Number of Days to Current ZonedDateTime

Tags: Java ZonedDateTime

In this Java tutorial, we learn how to add a number of days into current ZonedDateTime value in Java programming language.

How to add number of days to current ZonedDateTime in Java

We can follow these steps to add number of days into current ZonedDateTime value.

  • Instantiate the current ZonedDateTime object using the ZonedDateTime.now() static method.
  • Use the ZonedDateTime.plusDays(long days) method to create new ZonedDateTime object with number of days added.

AddDaysToCurrentZonedDateTimeExample.java

import java.time.ZonedDateTime;

public class AddDaysToCurrentZonedDateTimeExample {
    public static void main(String... args) {
        int numberOfDays = 20;

        // Add Number of Days to Current ZonedDateTime
        ZonedDateTime currentZoneDateTime = ZonedDateTime.now();
        ZonedDateTime newZonedDateTime = currentZoneDateTime.plusDays(numberOfDays);

        System.out.println("Number of days: " + numberOfDays);
        System.out.println("Current ZonedDateTime: " + currentZoneDateTime);
        System.out.println("New ZonedDateTime: " + newZonedDateTime);
    }
}
The output as below.
Number of days: 20
Current ZonedDateTime: 2022-09-07T20:28:16.162535700+07:00[Asia/Bangkok]
New ZonedDateTime: 2022-09-27T20:28:16.162535700+07:00[Asia/Bangkok]

Happy Coding 😊

Java Add Number of Days to Current Date

Java Add Number of Days to Current LocalDate

Java Add Number of Days to Current LocalDateTime

Java Add Number of Days to Current OffsetDateTime

How to Use TemporalAdjusters in Java

How to Sort a List of Date in Java