1. LocalDate、LocalTime、LocalDateTime函数
LocalDateTime的方法code
static LocalDateTime now() static of(int year, int month, int dayOfMonth, int hour, int minute, int second) LocalDateTime plusYears(long years) LocalDateTime minusYears(long years) int getYear() int getMonthValue() int getDayOfMonth() int getHour() int getMinute() getSecond() String format(DateTimeFormatter formatter) static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter) //方法返回此LocalDateTime的副本,其中包含每日更改的日期。 LocalDateTime withDayOfMonth(int dayOfMonth) //方法返回此LocalDateTime的副本,其中包含每日更改的日期。 LocalDateTime with(TemporalAdjuster adjuster)
2. Instant : 时间戳。 (使用 Unix 元年 1970年1月1日 00:00:00 所经历的毫秒值)orm
static Instant now() OffsetDateTime atOffset(ZoneOffset offset) int getNano() static Instant ofEpochSecond(long epochSecond) //使用1970-01-01T00:00:00Z的纪元中的秒来获取Instant的实例
ZoneOffset的方法接口
static ZoneOffset ofHours(int hours)
3. Duration的方法 :get
// 用于计算两个“时间”间隔 //public final class Instant implements Temporal static Duration between(Temporal startInclusive, Temporal endExclusive) long getSeconds() long toMillis()
Period的方法 :it
//用于计算两个“日期”间隔 static Period between(LocalDate startDateInclusive, LocalDate endDateExclusive) int getYears() int getMonths() int getDays()
4. TemporalAdjuster : 时间校订器,函数式接口io
TemporalAdjusters的方法form
static TemporalAdjuster next(DayOfWeek dayOfWeek)
//自定义:下一个工做日 LocalDateTime ldt5 = ldt.with((l) -> { LocalDateTime ldt4 = (LocalDateTime) l; DayOfWeek dow = ldt4.getDayOfWeek(); if(dow.equals(DayOfWeek.FRIDAY)){ return ldt4.plusDays(3); }else if(dow.equals(DayOfWeek.SATURDAY)){ return ldt4.plusDays(2); }else{ return ldt4.plusDays(1); } });
5. DateTimeFormatter : 解析和格式化日期或时间
class
static DateTimeFormatter ofPattern(String pattern) String format(TemporalAccessor temporal)
6.ZonedDate、ZonedTime、ZonedDateTime : 带时区的时间或日期sso