java8时间处理
public static void main(String[] args) {
LocalDate today = LocalDate.now();
System.out.println(today);
LocalDate birthday = LocalDate.of(1994,8,11);
System.out.println(birthday);
if (today.equals(birthday)) {
System.out.println("日期形同");
}
MonthDay myBithday = MonthDay.of(birthday.getMonth(), birthday.getDayOfMonth());
MonthDay currentMonDay = MonthDay.from(today);
if (myBithday.equals(currentMonDay)) {
System.out.println("今天是你的生日");
}
LocalDateTime nowTime = LocalDateTime.now();
LocalDateTime afterTime = nowTime.plusHours(3);
LocalDateTime beforeTime = nowTime.minusYears(2);
System.out.println("afterTime:"+afterTime+"- beforeTime:"+beforeTime);
LocalDateTime localDateTime = nowTime.withHour(11);
System.out.println("with 11 Time:"+localDateTime);
Clock clock = Clock.systemUTC();
System.out.println(clock.millis());
System.out.println(System.currentTimeMillis());
Clock defalutClock = Clock.systemDefaultZone();
System.out.println(defalutClock.millis());
System.out.println(defalutClock.getZone());
LocalDateTime tomorrow = nowTime.plusDays(1);
if (tomorrow.isEqual(nowTime)) {
} else if (tomorrow.isAfter(nowTime)) {
} else if (tomorrow.isBefore(nowTime)) {
} else {
}
ZoneId beijing = ZoneId.of("America/New_York");
LocalDateTime timenow = LocalDateTime.now();
ZonedDateTime zonedDateTime = ZonedDateTime.of(timenow, beijing);
System.out.println("纽约时间" + zonedDateTime);
LocalDate leafYear = LocalDate.now();
if (leafYear.isLeapYear()){
}
LocalDate current = LocalDate.now();
LocalDate yourBirthday = LocalDate.of(1996, 8, 11);
Period between = Period.between(yourBirthday, current);
System.out.println(between.getYears()+"年"+between.getMonths()+"月"+between.getDays()+"天");
LocalDateTime dateTime = LocalDateTime.now();
ZoneOffset offset = ZoneOffset.of("+05:30");
OffsetDateTime offsetDateTime = OffsetDateTime.of(dateTime, offset);
System.out.println(offsetDateTime);
System.out.println(OffsetDateTime.now());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
System.out.println(formatter.format(LocalDateTime.now()));
}