/**
* LocalDate,LocalDateTime,localTime类
*/
@Test
public void local(){
//static LocalDate now()
//从默认时区的系统时钟获取当前日期。
LocalDate localDate = LocalDate.now();
System.out.println(localDate);//2020-09-03
//static LocalDate now()
//从默认时区的系统时钟获取当前的日期时间。
LocalDateTime localDateTime = LocalDateTime.now();
System.out.println(localDateTime);//2020-09-03T17:16:15.270
//int getDayOfMonth()
//获取月份字段。
//DayOfWeek getDayOfWeek()
//获取星期几字段,这是一个枚举 DayOfWeek 。
//int getDayOfYear()
//获得日期字段。
//int getHour()
//获取时间字段。
System.out.println(localDateTime.getDayOfMonth());
System.out.println(localDateTime.getDayOfWeek());
System.out.println(localDateTime.getDayOfYear());
System.out.println(localDateTime.getHour());
LocalTime localTime = LocalTime.now();
System.out.println(localTime);//17:23:37.642
}
}
附加
/**
* instant
*/
@Test
public void instant(){
//static Instant now()
//从系统时钟获取当前瞬间。
Instant instant = Instant.now();
System.out.println(instant);//2020-09-03T09:38:06.694Z,不是北京时间,少8h
}