Unix timestamp
是1417029117
,即2014年11月26日,星期三。
long timestamp = 1417029117l*1000l;
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(timestamp);
System.out.println("current day is "+cal.get(Calendar.DAY_OF_WEEK));
System.out.println("current month is "+cal.get(Calendar.MONTH));
我得到的结果如下:
current day is 4
current month is 10
有什么解释吗?如果一月是0
那么这个月很好。但为什么这一天4
?
一周的第一天是星期日。所以,星期三是4。请参阅日历#DAY_OF_WEEK和常量字段值,日历#星期三,这在文档中很明显。