public static Instant getMonthEnd ( Instant time ) { Assert . notNull ( time , "Missing date time" ) ; LocalDateTime dateTime = LocalDateTime . ofInstant ( time , ZoneOffset . UTC ) ; dateTime = dateTime . withDayOfMonth ( 1 ) . withHour ( 23 ) . withMinute ( 59 ) . withSecond ( 59 ) . with ( ChronoField . MILLI_OF_SECOND , 999 ) ; dateTime = dateTime . plus ( 1 , ChronoUnit . MONTHS ) . minus ( 1 , ChronoUnit . DAYS ) ; return dateTime . toInstant ( ZoneOffset . UTC ) ; }
Returns last millisecond of last day in month ... + 1 = next first day in month