Example usage for java.time LocalDate plus

List of usage examples for java.time LocalDate plus

Introduction

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

Prototype

@Override
public LocalDate plus(long amountToAdd, TemporalUnit unit) 

Source Link

Document

Returns a copy of this date with the specified amount added.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.of(2014, 6, 30);
    LocalDate b = a.plus(100, ChronoUnit.DAYS);
    System.out.println(b);/*from w ww  . j ava  2s.  co  m*/
}

From source file:Main.java

public static void main(String... args) {
    LocalDate today = LocalDate.now();
    LocalDate tomorrow = today.plus(1, ChronoUnit.DAYS);
    LocalDate yesterday = tomorrow.minusDays(2);

    System.out.println(today);/*  www.  j a v  a2  s.  c  o  m*/
    System.out.println(tomorrow);
    System.out.println(yesterday);

}

From source file:Main.java

public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2012, 11, 23);
    System.out.println(localDate.plus(3, ChronoUnit.DAYS)); //2012-11-26

    System.out.println(localDate.plus(Period.ofDays(3))); //2012-11-26
    try {//from w w w . j  a v a  2s  .c o m
        System.out.println(localDate.plus(Duration.ofDays(3)));

        System.out.println(localDate.plus(4, ChronoUnit.FOREVER));
    } catch (UnsupportedTemporalTypeException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate february20th = LocalDate.of(2014, Month.FEBRUARY, 20);
    System.out.println(february20th);
    System.out.println(LocalDate.from(february20th.plus(15, ChronoUnit.YEARS))); // 2029-02-20
    System.out.println(LocalDate.MAX);
    System.out.println(LocalDate.MIN);

    System.out.println(LocalTime.MIDNIGHT); // 00:00
    System.out.println(LocalTime.NOON); // 12:00
    System.out.println(LocalTime.of(23, 12, 30, 500)); // 23:12:30.000000500
    System.out.println(LocalTime.now()); // 00:40:34.110
    System.out.println(LocalTime.ofSecondOfDay(11 * 60 * 60)); // 11:00
    System.out.println(LocalTime.from(LocalTime.MIDNIGHT.plusHours(4))); // 04:00
    System.out.println(LocalTime.MIN);
    System.out.println(LocalTime.MAX);

    System.out.println(LocalDateTime.of(2014, 2, 15, 12, 30, 50, 200)); // 2014-02-15T12:30:50.000000200
    System.out.println(LocalDateTime.now()); // 2014-02-28T17:28:21.002
    System.out.println(LocalDateTime.from(LocalDateTime.of(2014, 2, 15, 12, 30, 40, 500).plusHours(19))); // 2014-02-16T07:30:40.000000500
    System.out.println(LocalDateTime.MAX);
}

From source file:Main.java

public static void main(String[] argv) {
    LocalDate today = LocalDate.now();
    LocalDate tomorrow = today.plusDays(1);
    LocalDateTime time = LocalDateTime.now();
    LocalDateTime nextHour = time.plusHours(1);

    System.out.println("today = " + today);
    System.out.println("1) tomorrow = " + tomorrow + " \n2) tomorrow = " + today.plus(1, DAYS));
    System.out.println("local time now = " + time);
    System.out.println("1) nextHour = " + nextHour + " \n2) nextHour = " + time.plus(1, HOURS));

    LocalDate nextWeek = today.plus(1, WEEKS);
    System.out.println("Date after 1 week : " + nextWeek);

    LocalDate previousYear = today.minus(1, YEARS);
    System.out.println("Date before 1 year : " + previousYear);

    LocalDate nextYear = today.plus(1, YEARS);
    System.out.println("Date after 1 year : " + nextYear);

    LocalDate firstDayOfMonth = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
    System.out.println("firstDayOfMonth = " + firstDayOfMonth);
}

From source file:com.epam.ta.reportportal.core.project.impl.ProjectInfoWidgetDataConverter.java

/**
 * Utility method for grouping input list of {@link Launch} by
 * {@link ProjectInfoGroup} criteria//w w w.ja  v  a2 s  .  co  m
 * 
 * @param initial
 * @param criteria
 * @return
 */
private static Map<String, List<Launch>> groupBy(List<Launch> initial, ProjectInfoGroup criteria) {
    Map<String, List<Launch>> result = new LinkedHashMap<>();
    LocalDate prevDate = null;
    for (Launch launch : initial) {
        final LocalDate localDate = launch.getStartTime().toInstant().atZone(ZoneId.systemDefault())
                .toLocalDate();

        String key;
        switch (criteria) {
        case BY_NAME:
            key = launch.getName();
            break;
        default:
            key = formattedDate(criteria, localDate);
            if (prevDate != null) {
                while (!formattedDate(criteria, prevDate).equals(formattedDate(criteria, localDate))) {
                    if (!result.containsKey(formattedDate(criteria, prevDate)))
                        result.put(formattedDate(criteria, prevDate), new ArrayList<>());
                    prevDate = prevDate.plus(1, criteria == BY_DAY ? DAYS : WEEKS);
                }
            }
        }
        if (!result.keySet().contains(key))
            result.put(key, Lists.newArrayList(launch));
        else {
            List<Launch> prev = result.get(key);
            prev.add(launch);
            result.put(key, prev);
        }
        prevDate = localDate;
    }
    return result;
}

From source file:org.darkware.wpman.util.TimeWindow.java

/**
 * Calculates the next time when a given hour and minute occur, based from the given start time.
 *
 * @param after The time to start searching from.
 * @param hour The hour to search for./*  w w w. java2  s.  co m*/
 * @param minute The minute to search for.
 * @return A {@code DateTime} corresponding to the hour and minute declared which is explicitly after
 * the start time.
 */
public static LocalDateTime nextTime(final LocalDateTime after, final int hour, final int minute) {
    LocalTime time = LocalTime.of(hour, minute);
    LocalDate afterDate = after.toLocalDate();
    if (!time.isAfter(after.toLocalTime()))
        afterDate = afterDate.plus(1, ChronoUnit.DAYS);
    return time.atDate(afterDate);
}