Java Date Time - ZonedDateTime with(TemporalAdjuster adjuster) example








ZonedDateTime with(TemporalAdjuster adjuster) returns an adjusted copy of this date-time.

Syntax

with has the following syntax.

public ZonedDateTime with(TemporalAdjuster adjuster)

Example

The following example shows how to use with.

import java.time.ZonedDateTime;
import java.time.temporal.TemporalAdjusters;
//from  ww  w.  ja  va 2s.  co m
public class Main {
  public static void main(String[] args) {
    ZonedDateTime dateTime =ZonedDateTime.now();
    dateTime = dateTime.with(TemporalAdjusters.firstDayOfMonth());
    System.out.println(dateTime);
  } 
}

The code above generates the following result.