List of usage examples for java.time LocalDate minus
@Override public LocalDate minus(long amountToSubtract, TemporalUnit unit)
From source file:Main.java
public static void main(String[] args) { LocalDate a = LocalDate.of(2014, 6, 30); LocalDate b = a.minus(6, ChronoUnit.YEARS); System.out.println(b);//from ww w. ja va 2 s . co m }
From source file:Main.java
public static void main(String[] argv) { LocalDate today = LocalDate.now(); LocalDate tomorrow = today.plusDays(1); LocalDate yesterday = today.minus(1, DAYS); if (tomorrow.isAfter(today)) { System.out.println("Tomorrow comes after today"); }/* ww w. j a v a2s . c o m*/ if (yesterday.isBefore(today)) { System.out.println("Yesterday is day before today"); } }
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:Main.java
/** * The methods calculates the previous working day. It only recognize Saturday * and Sunday as non -working days./* w w w . j a v a 2 s.com*/ * * @param date * Date as starting point for the calculation, cannot be null * @return The previous working day */ public static LocalDate getPreviousWorkingDay(LocalDate date) { DayOfWeek dayOfWeek = DayOfWeek.of(date.get(ChronoField.DAY_OF_WEEK)); switch (dayOfWeek) { case MONDAY: return date.minus(3, ChronoUnit.DAYS); case SUNDAY: return date.minus(2, ChronoUnit.DAYS); default: return date.minus(1, ChronoUnit.DAYS); } }
From source file:nu.yona.server.analysis.service.ActivityService.java
private Interval getInterval(LocalDate currentUnitDate, Pageable pageable, ChronoUnit timeUnit) { LocalDate startDate = currentUnitDate.minus(pageable.getOffset() + pageable.getPageSize() - 1L, timeUnit); LocalDate endDate = currentUnitDate.minus(pageable.getOffset() - 1L, timeUnit); return Interval.createInterval(startDate, endDate); }