Example usage for java.time LocalDate with

List of usage examples for java.time LocalDate with

Introduction

In this page you can find the example usage for java.time LocalDate with.

Prototype

@Override
public LocalDate with(TemporalAdjuster adjuster) 

Source Link

Document

Returns an adjusted copy of this date.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.of(2014, 6, 30);
    LocalDate b = a.with(TemporalAdjusters.firstDayOfMonth());
    System.out.println(b);/* w w  w .j a va2  s  .  com*/
}

From source file:Main.java

public static void main(String[] argv) {
    LocalDate today = LocalDate.now();
    LocalDate longestDay = today.with(Month.JUNE).withDayOfMonth(21);
    int p = Period.between(today, longestDay).getDays();
    System.out.println(p);//  w  w  w. j a va2 s .c  o m
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate today = LocalDate.now();

    LocalDate monday = today.with(previousOrSame(MONDAY));
    LocalDate sunday = today.with(nextOrSame(SUNDAY));

    System.out.println("Today: " + today);
    System.out.println("Monday of the Week: " + monday);
    System.out.println("Sunday of the Week: " + sunday);
}

From source file:Main.java

public static void main(String[] args) {
    // Create an adjuster that retruns a date after 3 months and 2 days
    TemporalAdjuster adjuster = TemporalAdjusters
            .ofDateAdjuster((LocalDate date) -> date.plusMonths(3).plusDays(2));

    LocalDate today = LocalDate.now();
    LocalDate dayAfter3Mon2Day = today.with(adjuster);
    System.out.println("Today: " + today);
    System.out.println("After 3  months  and  2  days: " + dayAfter3Mon2Day);

}

From source file:Main.java

public static void main(String[] args) {
    LocalDate july_2014 = LocalDate.of(2014, 7, 20);
    LocalDate nextPayday = july_2014.with(new FirstTuesdayAdjuster());
    System.out.println(nextPayday);
    LocalDate august_2009 = LocalDate.of(2009, 8, 20);
    nextPayday = august_2009.with(new FirstTuesdayAdjuster());
    System.out.println(nextPayday);
}

From source file:Main.java

public static void main(String[] args) {
    TemporalAdjuster temporalAdjuster = (Temporal t) -> t.plus(Period.ofDays(10));

    System.out.println(temporalAdjuster);

    TemporalAdjuster fourMinutesFromNow = temporal -> temporal.plus(4, ChronoUnit.MINUTES);

    LocalTime localTime1 = LocalTime.of(12, 0, 0);
    System.out.println(localTime1.with(temporal -> temporal.plus(4, ChronoUnit.MINUTES)));

    System.out.println(Instant.now().with(temporalAdjuster));

    LocalDate localDate1 = LocalDate.of(2013, 12, 13);
    System.out.println(localDate1.with(TemporalAdjusters.lastDayOfMonth()));

}

From source file:Main.java

public static void main(String[] args) {
    LocalDate ld1 = LocalDate.of(2014, Month.MAY, 21);
    System.out.println(ld1);//from  w w  w. ja v  a  2 s . c  om
    LocalDate ld2 = ld1.with(TemporalAdjusters.dayOfWeekInMonth(5, DayOfWeek.SUNDAY));
    System.out.println(ld2);
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate date = LocalDate.of(2014, Month.JULY, 16);
    System.out.println(date);//from   w  w w . j  ava  2  s.  com

    LocalDate firstDayOfJuly = date.with(TemporalAdjusters.firstDayOfMonth()); // 2014-07-01
    System.out.println(firstDayOfJuly);

    LocalDate dateOfFirstMonday = date.with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY)); // 2014-07-07
    System.out.println(dateOfFirstMonday);

}

From source file:Main.java

public static void main(String[] args) {
    LocalDate date = LocalDate.of(2014, Month.FEBRUARY, 25); // 2014-02-25

    // next Sunday (2014-03-02)
    LocalDate nextSunday = date.with(TemporalAdjusters.next(DayOfWeek.SUNDAY));

    System.out.println(nextSunday);
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate date = LocalDate.of(2014, Month.FEBRUARY, 25); // 2014-02-25

    // last day of 2014 (2014-12-31)
    LocalDate lastDayOfYear = date.with(TemporalAdjusters.lastDayOfYear());

    System.out.println(lastDayOfYear);
}