在Java中,可以使用以下方法給Calendar類賦值:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 2021);
calendar.set(Calendar.MONTH, Calendar.JANUARY);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
Calendar calendar = Calendar.getInstance();
calendar.set(2021, Calendar.JANUARY, 1, 12, 0, 0);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = "2021-01-01 12:00:00";
Date date = sdf.parse(dateString);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
以上是三種常見的給Calendar類賦值的方法,具體選擇哪種方法取決于你的需求和代碼的上下文。