static方法
主要是用来构建时间戳ZoneDateTime对象
方法 | 描述 |
---|---|
from(TemporalAccessor temporal) | 从时间对象获取,TemporalAccessor 就是time包下有关时间的类 |
now([ZoneId]) | 当前时间,可以指定ZoneId,这样就不必使用withSame.. 那个函数了 |
of(int year, int month, int dayOfMonth, int hour, int minute, int second) | 从整数获取 |
ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset) | 整形时间戳获取 |
ofInstant(Instant instant, ZoneId zone) | Instant对象获取 |
of(LocalDateTime localDateTime, ZoneId zone) | |
of(LocalDate date, LocalTime time, ZoneId zone) | 这俩对象获取 |
parse(CharSequence text) | 从字符串获取,国际标准ISO格式的2007-12-03T10:15:30 |
parse(CharSequence text, DateTimeFormatter formatter) | 也可以自己指定 |
instance方法
1.获取时间组件
首先提供了一个get()
通用方法,参数是ChronoField类型中的可用的字段
又提供了便捷的方法
int getDayOfMonth()
DayOfWeek getDayOfWeek()
int getDayOfYear()
int getHour()
long getLong(TemporalField field)
int getMinute()
Month getMonth()
int getMonthValue()
int getNano()
int getSecond()
int getYear()
2.比较
isBefore
isAfter
3.加减
plus
plusSeconds
…
minus
minusSeconds
…
4.更改时区
withZoneSameInstant(ZoneId zone)
5.转换
LocalDate toLocalDate()
LocalDateTime toLocalDateTime()
LocalTime toLocalTime()
OffsetDateTime toOffsetDateTime()
String toString()
参考:
https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html