Java实现 获取当前时间的年月日和星期:
具体代码如下:
import java.time.LocalDate;
public class DateTest7 {
public static void main(String[] args) {
LocalDate time = LocalDate.now();
// 得到当前时间所在年
int year = time.getYear();
System.out.println("当前年份 " + year);
// 得到当前时间所在月
int month = time.getMonth().getValue();
System.out.println("当前月份 " + month);
// 得到当前时间所在月
int day = time.getDayOfMonth();
System.out.println("当前日 " + day);
// 得到当前时间所在星期数
int dayOfWeek = time.getDayOfWeek().getValue();
System.out.println("当前星期 " + dayOfWeek);
}
}



