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 date = LocalDate.of(2014, Month.FEBRUARY, 25); // 2014-02-25

    // last day of February 2014 (2014-02-28)
    LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
    System.out.println(lastDayOfMonth);
}

From source file:Main.java

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

    // Temporal adjusters for adjusting the dates
    System.out.println("First date of this month= " + today.with(TemporalAdjusters.firstDayOfMonth()));
    LocalDate lastDayOfYear = today.with(TemporalAdjusters.lastDayOfYear());
    System.out.println("Last date of this year= " + lastDayOfYear);

    Period period = today.until(lastDayOfYear);
    System.out.println("Period Format= " + period);
    System.out.println("Months remaining in the year= " + period.getMonths());

}

From source file:Main.java

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

    // first day of February 2014 (2014-02-01)
    LocalDate firstDayOfMonth = date.with(TemporalAdjusters.firstDayOfMonth());

    System.out.println(firstDayOfMonth);
}

From source file:Main.java

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

    // first day of next month (2014-03-01)
    LocalDate firstDayOfNextMonth = date.with(TemporalAdjusters.firstDayOfNextMonth());

    System.out.println(firstDayOfNextMonth);
}

From source file:Main.java

public static void main(String[] args) {
    Month month = Month.valueOf("March".toUpperCase());

    System.out.printf("For the month of %s:%n", month);
    LocalDate date = Year.now().atMonth(month).atDay(1).with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY));
    Month mi = date.getMonth();//ww  w  .  ja v a  2 s .c o  m
    while (mi == month) {
        System.out.printf("%s%n", date);
        date = date.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
        mi = date.getMonth();
    }
}

From source file:Main.java

public static void main(String[] args) {
    Month month = null;//from  w w  w .  j  a v  a 2  s.c o  m
    LocalDate date = null;
    DateTimeFormatter format;
    String out = null;

    month = Month.valueOf("May".toUpperCase());
    date = Year.now().atMonth(month).atDay(12);

    LocalDate nextPayday = date.with(new PaydayAdjuster());

    format = DateTimeFormatter.ofPattern("yyyy MMM d");
    out = date.format(format);
    System.out.printf("Given the date:  %s%n", out);
    out = nextPayday.format(format);
    System.out.printf("the next payday: %s%n", out);
}

From source file:ListMondays.java

public static void main(String[] args) {
    Month month = null;//from   w  w w  .ja  v  a 2  s .  co m

    if (args.length < 1) {
        System.out.printf("Usage: ListMondays <month>%n");
        throw new IllegalArgumentException();
    }

    try {
        month = Month.valueOf(args[0].toUpperCase());
    } catch (IllegalArgumentException exc) {
        System.out.printf("%s is not a valid month.%n", args[0]);
        throw exc; // Rethrow the exception.
    }

    System.out.printf("For the month of %s:%n", month);
    LocalDate date = Year.now().atMonth(month).atDay(1).with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY));
    Month mi = date.getMonth();
    while (mi == month) {
        System.out.printf("%s%n", date);
        date = date.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
        mi = date.getMonth();
    }
}

From source file:com.github.drbookings.LocalDates.java

public static LocalDate getLastDayOfMonth(final LocalDate date) {
    return date.with(TemporalAdjusters.lastDayOfMonth());
}

From source file:Main.java

@Override
public Quarter queryFrom(TemporalAccessor temporal) {
    LocalDate now = LocalDate.from(temporal);

    if (now.isBefore(now.with(Month.APRIL).withDayOfMonth(1))) {
        return Quarter.FIRST;
    } else if (now.isBefore(now.with(Month.JULY).withDayOfMonth(1))) {
        return Quarter.SECOND;
    } else if (now.isBefore(now.with(Month.NOVEMBER).withDayOfMonth(1))) {
        return Quarter.THIRD;
    } else {/*from w w  w .jav  a 2 s .  com*/
        return Quarter.FOURTH;
    }
}

From source file:Main.java

@Override
public Temporal adjustInto(Temporal input) {
    LocalDate date = LocalDate.from(input);
    LocalDate nextMonth = date.plusMonths(1);
    LocalDate firstTuesdayInNextMonth = nextMonth.with(TemporalAdjusters.firstInMonth(DayOfWeek.TUESDAY));
    return input.with(firstTuesdayInNextMonth);
}