我的时间戳以毫秒为单位,即 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/