Java 如何检查毫秒时间戳是否在我当前时区的午夜?
我有一个以毫秒为单位的时间戳,它是Java 如何检查毫秒时间戳是否在我当前时区的午夜?,java,time,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 *
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;