Calendar方法获取当前年月日
时间: 2023-05-20 18:01:58 浏览: 94
获取当前月日期
您好,可以使用以下代码获取当前年月日:
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println("当前日期为:" + year + "年" + month + "月" + day + "日");
}
}
阅读全文