public static long nextMonthStartTimeMilli(long timestamp) {
Clock clock = Clock.fixed(Instant.ofEpochMilli(timestamp),DEFAULT_ZONE_ID);
Month nextMonth = MonthDay.now(clock).getMonth().plus(1);
return LocalDate.now(clock)
.with(MonthDay.of(nextMonth,1))
.atStartOfDay(DEFAULT_ZONE_ID)
.toInstant()
.toEpochMilli();
}
public static long nextWeekStartTimeMilli(long timestamp) {
return LocalDate.now(Clock.fixed(Instant.ofEpochMilli(timestamp),DEFAULT_ZONE_ID))
.plusWeeks(1)
.with(DayOfWeek.MONDAY)
.atStartOfDay(DEFAULT_ZONE_ID)
.toInstant()
.toEpochMilli();
}
public static long tomorrowStartTimeMilli(long timestamp) {
return LocalDate.now(Clock.fixed(Instant.ofEpochMilli(timestamp),DEFAULT_ZONE_ID))
.plusDays(1)
.atStartOfDay(DEFAULT_ZONE_ID)
.toInstant()
.toEpochMilli();
}
/**
* 距离下个自然月剩余的毫秒数
*@return
*/
public static long nextMonthLeftTimeMilli() {
long now = System.currentTimeMillis();
return nextMonthStartTimeMilli(now) - now;
}
/**
* 距离下个周一剩余的毫秒数
*@return
*/
public static long nextWeekLeftTimeMilli() {
long now = System.currentTimeMillis();
return nextWeekStartTimeMilli(now) - now;
}
/**
* 距离明天剩余的毫秒数
*@return
*/
public static long tomorrowLeftTimeMilli() {
long now = System.currentTimeMillis();
return tomorrowStartTimeMilli(now) - now;
}