Calendar.getTimeInMillis()为同一实例返回不同的结果 [英] Calendar.getTimeInMillis() returns different results for same instance
本文介绍了Calendar.getTimeInMillis()为同一实例返回不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码并在Calendar实例上调用getTimeInMillis()。我希望返回值相同但在运行之间返回不同的结果。
I have the following code and calling getTimeInMillis() on a Calendar instance. I expect the return value to be same but it returns different results between runs.
结果如下所示,这是不同的。我做错了什么,需要改变什么?
The results were coming as below which are different. What am i doing wrong and what needs to be changed?
时间1369454400208
时间1369454400185
时间1369454400926
Time 1369454400208 Time 1369454400185 Time 1369454400926
public class MyTest {
public static void main(String[] args){
Calendar calendar = new GregorianCalendar();
calendar.set(calendar.YEAR, 2013);
calendar.set(calendar.MONTH, 4);
calendar.set(calendar.DATE, 24);
calendar.set(calendar.HOUR, 12);
calendar.set(calendar.MINUTE, 00);
calendar.set(calendar.SECOND, 00);
System.out.print("Time " + calendar.getTimeInMillis());
}
推荐答案
你需要也重置毫秒。
calendar.set(Calendar.MILLISECOND, 0);
注意你应该使用 Calendar。*
来访问静态字段,而不是日历。*
。
Note you should use Calendar.*
to access static fields, not calendar.*
.
这篇关于Calendar.getTimeInMillis()为同一实例返回不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文