在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类赋值的方法,具体选择哪种方法取决于你的需求和代码的上下文。