java - 如何检查毫秒时间戳是否在我当前时区的午夜?

标签 java time

我的时间戳以毫秒为单位,即 1349557200000。我如何检查它是否发生在我当前时区的午夜?

我想出的最好的办法是:

Calendar mycal = Calendar.getInstance();
Integer offset = (mycal.get(Calendar.ZONE_OFFSET) + mycal.get(Calendar.DST_OFFSET)) * (60 * 1000);
Boolean isAtMidnight = 1349557200000L % (24L * 60L * 60L * 1000L)) == (long) offset ? true : false;

这看起来有点复杂。我想知道是否有任何我可能缺少的快捷方法。谢谢。

最佳答案

Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(milliseconds);
return cal.get(Calendar.HOUR_OF_DAY) == 0
       && cal.get(Calendar.MINUTE) == 0
       && cal.get(Calendar.SECOND) == 0
       && cal.get(Calendar.MILLISECOND) == 0;

关于java - 如何检查毫秒时间戳是否在我当前时区的午夜?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12688950/

相关文章:

java - 发布 :perform from my maven build 时收到 401 错误代码

Java - 索引接口(interface)?

php - MySQL 将时间范围分割成更小的 block

Java-设置 datetime17 :30 if the current time is before 17:00

c++ - Linux:GetDateFormat() 和 GetTimeFormat() 是否存在 C++?

java - 如何匹配字符串输入

java - Tomcat/Java 调试信息

java - Android 按钮只能在角落点击

python - 如何在python3上打印当前日期?

swift - 获取当前时间作为字符串 swift 3.0