获取当前的日期 LocalDate
LocalDate today = LocalDate . now ( ) ;
System . out. println ( "今天是:" + today) ;
String format = today. format ( DateTimeFormatter . ofPattern ( "yyyy年MM月dd日" ) ) ;
System . out. println ( "今天是:" + format) ;
String format1 = today. format ( DateTimeFormatter . ofPattern ( "yyyy年MM月dd日" ) ) ;
System . out. println ( "今天是:" + format1) ;
获取年月日
LocalDate today = LocalDate . now ( ) ;
int year = today. getYear ( ) ;
int month = today. getMonthValue ( ) ;
int day = today. getDayOfMonth ( ) ;
System . out. printf ( "Year: %d Month: %d Day: %d%n" , year, month, day) ;
日期创建
LocalDate today = LocalDate . of ( 2017 , 9 , 1 ) ;
System . out. println ( "today = " + today) ;
两个日期判断是否相等
LocalDate today = LocalDate . now ( ) ;
LocalDate before = LocalDate . of ( 2017 , 9 , 1 ) ;
if ( today. equals ( before) ) System . out. println ( "相等" ) ;
else System . out. println ( "不相等" ) ;
YearMonth
YearMonth currentYearMonth = YearMonth . now ( ) ;
System . out. printf ( "当前是 %s 本月共: %d 天 %n" , currentYearMonth, currentYearMonth. lengthOfMonth ( ) ) ;
YearMonth creditCardExpiry = YearMonth . of ( 2029 , Month . APRIL ) ;
System . out. printf ( "你的信用卡将于 %s 到期" , creditCardExpiry) ;
周期性时间
LocalDate today = LocalDate . now ( ) ;
LocalDate birthdayDate = LocalDate . of ( 2017 , 9 , 1 ) ;
MonthDay birthday = MonthDay . of ( birthdayDate. getMonth ( ) , birthdayDate. getDayOfMonth ( )