Working with Dates in Java 8 is easy and intuitive.
LocalDateTime currTime = LocalDateTime.now();
int currentYear = currTime.getYear();
int currentMonth = currTime.getMonthValue();
// prepare @datum_start = last day of previous month
LocalDateTime datumStart =
currTime.minusMonths(1L)
.with(TemporalAdjusters.lastDayOfMonth());
// prepare @datum_end = first day of next month
LocalDateTime datumEnd =
currTime.withDayOfMonth(1)
.plusMonths(1L);
//convert to java.util.Date
LocalDateTime ldt = LocalDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault());
Date out = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
More info here.
