日历时间转换

Calendar time convertation

当我尝试将日期转换为毫秒时发生了一些奇怪的事情。也许有人可以解释我的这个:

 Calendar calendar = Calendar.getInstance();
 calendar.set(2017, 9, 3, 4, 50);

 SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd hh:mm:ss",
     Locale.getDefault());
 Log.i("tag", formatter.format(calendar.getTime()));

and logcat logs my out:

I/tag: 2017.10.03 04:50:34

为什么月份不同?

Calendar 月份是从零开始的 (0-11),但显示时是 "human" 版本 (1-12)。

在方法calendar.set()中,根据文档参数月从0开始。

month the value used to set the MONTH calendar field. * Month value is 0-based. e.g., 0 for January.