java8 获取精确到分钟/秒的时间戳
/** * 获取分钟的时间戳 * * @return */ private static long getTimeMills() { LocalDate localDate = LocalDate.now(); LocalTime localTime = LocalTime.now(); return LocalDateTime.of(localDate.getYear(), localDate.getMonth(), localDate.getDayOfMonth(), localTime.getHour(), localTime.getMinute(), 0) .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); }
/** * 获取精确到秒的时间戳 * * @return */ private static long getTimeMills() { LocalDate localDate = LocalDate.now(); LocalTime localTime = LocalTime.now(); return LocalDateTime.of(localDate.getYear(), localDate.getMonth(), localDate.getDayOfMonth(), localTime.getHour(), localTime.getMinute(), localTime.getSecond()) .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); }
获取当天整点的时间戳:
/** * 获取明天零点时间戳 * * @return */ private long getExpireTimeStamp() { LocalDate localDate = LocalDate.now() // LocalDate localDate = LocalDate.now().plusDays(1); return LocalDateTime.of(localDate.getYear(), localDate.getMonth(), localDate.getDayOfMonth(), 0, 0, 0) .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); }