我的关注 |
¥0.1 java如何判断一个时间戳是否是昨天?
0

java如何判断一个时间戳是否是昨天?

hong
修改
评论(0)
1个回答
0
采纳
  1. public class Test {
  2. private static long ONE_SECOND_MS = 1000;
  3. private static long ONE_DAY_MS = 24 * 60 * 60 * ONE_SECOND_MS;
  4. public static boolean IsYesterday(long yesterdayMS) {
  5. long now = System.currentTimeMillis();
  6. long todayLeftMS = todayLeftSeconds() * ONE_SECOND_MS;
  7. long a = now - yesterdayMS - (ONE_DAY_MS - todayLeftMS);
  8. return a >= 0 && a <= ONE_DAY_MS;
  9. }
  10. private static int todayLeftSeconds() {
  11. LocalDateTime now = LocalDateTime.now();
  12. LocalDateTime nextClock0 = LocalDateTime.of(LocalDate.now().plusDays(1L), LocalTime.MIN);
  13. return (int) ChronoUnit.SECONDS.between(now, nextClock0);
  14. }
  15. public static void main(String[] args) {
  16. System.out.println(IsYesterday(System.currentTimeMillis() - ONE_DAY_MS));
  17. }
  18. }
采纳答案
佛法不二
修改
评论 (0)
撰写回答