calendar.set(2023,1,1); 月份从0开始,表示1月,你是1,所以是2月份,当然是多了一个月的时间。
一月是0
void java.util.Calendar.set(int year, int month, int date)
Sets the values for the calendar fields YEAR, MONTH, and DAY_OF_MONTH. Previous values of other calendar fields are retained. If this is not desired, call clear() first.
Parameters:
year the value used to set the YEAR calendar field.
month the value used to set the MONTH calendar field. Month value is 0-based. e.g., 0 for January.
date the value used to set the DAY_OF_MONTH calendar field.