前言

ZoneOffset,LocalDateTime,LocalTime, YearMonth, Year, MonthDay,它们代表与上下文相结合的本地日期/时间。这些类主要用于不需要在上下文中明确指定时区的情况,他们是线程安全的

  类                 信息类别               输出案例
ZoneOffset          时区偏移量             +01:00
ZoneId               时区               Asia/Shanghai
ZonedDateTime                      2020-05-19T14:51:10.826+08:00[Asia/Shanghai]
OffsetDateTime                        2020-05-19T14:49:31.506+08:00
OffsetTime                             14:49:01.581+08:00

一、ZoneOffset

public final class ZoneOffset extends ZoneId implements TemporalAccessor, TemporalAdjuster, Comparable, Serializable

1、获取

static ZoneOffset   of(String offsetId)
static ZoneOffset   ofHours(int hours)
static ZoneOffset   ofHoursMinutes(int hours, int minutes)
static ZoneOffset   ofHoursMinutesSeconds(int hours, int minutes, int seconds)
static ZoneOffset   ofTotalSeconds(int totalSeconds)//获取 ZoneOffset的实例, ZoneOffset总偏移量(以秒为单位)
static ZoneOffset   from(TemporalAccessor temporal)//从时间对象获取一个 ZoneOffset的实例。

2、信息获取

int compareTo(ZoneOffset other)。。将此偏移量与其他偏移量按降序进行比较。
boolean equals(Object obj)。。检查这个偏移量是否等于另一个偏移量。int get(TemporalField field)。。从该偏移量获取指定字段的值作为 int 。
String  getId()//获取标准化区域偏移ID。
long    getLong(TemporalField field)//从该偏移量获取指定字段的值作为 long 。
ZoneRules   getRules()//获取相关的时区规则。
int getTotalSeconds()//获取总区域偏移量(以秒为单位)。
int hashCode()//这个偏移的哈希码。
boolean isSupported(TemporalField field)//检查指定的字段是否受支持。
<R> R   query(TemporalQuery<R> query)//使用指定的查询查询此偏移量。
ValueRange  range(TemporalField field)//获取指定字段的有效值的范围。
String  toString()//输出该偏移为 String ,使用归一化ID。

二、ZoneId

public abstract class ZoneId extends Object implements Serializable

1、获取

static ZoneId   of(String zoneId)//从ID获取一个 ZoneId的实例,确保该ID有效并且可供使用。
static ZoneId   of(String zoneId, Map<String,String> aliasMap)//获取 ZoneId的实例,使用其ID使用别名映射来补充标准区域ID。
static ZoneId   ofOffset(String prefix, ZoneOffset offset)//获得一个封装偏移量的 ZoneId的实例。
static ZoneId   systemDefault()
static ZoneId   from(TemporalAccessor temporal)//从时间对象获取一个 ZoneId的实例。

三、ZonedDateTime

public final class ZonedDateTime extends Object implements Temporal, ChronoZonedDateTime, Serializable

1、对象的创建

static ZonedDateTime now()
static ZonedDateTime now(Clock clock)
static ZonedDateTime now(ZoneId zone)
static ZonedDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneId zone)
static ZonedDateTime of(LocalDate date, LocalTime time, ZoneId zone)
static ZonedDateTime of(LocalDateTime localDateTime, ZoneId zone)static ZonedDateTime ofInstant(Instant instant, ZoneId zone)
static ZonedDateTime ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)static ZonedDateTime ofLocal(LocalDateTime localDateTime, ZoneId zone, ZoneOffset preferredOffset)static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)static ZonedDateTime parse(CharSequence text)
static ZonedDateTime parse(CharSequence text, DateTimeFormatter formatter)static ZonedDateTime    from(TemporalAccessor temporal)

2、时间计算

//加
ZonedDateTime   plus(long amountToAdd, TemporalUnit unit)
ZonedDateTime   plus(TemporalAmount amountToAdd)
ZonedDateTime   plusDays(long days)
ZonedDateTime   plusHours(long hours)
ZonedDateTime   plusMinutes(long minutes)
ZonedDateTime   plusMonths(long months)
ZonedDateTime   plusNanos(long nanos)
ZonedDateTime   plusSeconds(long seconds)
ZonedDateTime   plusWeeks(long weeks)
ZonedDateTime   plusYears(long years)//减
ZonedDateTime   minus(long amountToSubtract, TemporalUnit unit)
ZonedDateTime   minus(TemporalAmount amountToSubtract)
ZonedDateTime   minusDays(long days)
ZonedDateTime   minusHours(long hours)
ZonedDateTime   minusMinutes(long minutes)
ZonedDateTime   minusMonths(long months)
ZonedDateTime   minusNanos(long nanos)
ZonedDateTime   minusSeconds(long seconds)
ZonedDateTime   minusWeeks(long weeks)
ZonedDateTime   minusYears(long years)//自定义
ZonedDateTime   with(TemporalAdjuster adjuster)
ZonedDateTime   with(TemporalField field, long newValue)
ZonedDateTime   withDayOfMonth(int dayOfMonth)
ZonedDateTime   withDayOfYear(int dayOfYear)
ZonedDateTime   withEarlierOffsetAtOverlap()
ZonedDateTime   withFixedOffsetZone() //去除时区返回
ZonedDateTime   withHour(int hour)
ZonedDateTime   withLaterOffsetAtOverlap()
ZonedDateTime   withMinute(int minute)
ZonedDateTime   withMonth(int month)
ZonedDateTime   withNano(int nanoOfSecond)
ZonedDateTime   withSecond(int second)
ZonedDateTime   withYear(int year)
ZonedDateTime   withZoneSameInstant(ZoneId zone)
ZonedDateTime   withZoneSameLocal(ZoneId zone)

3、类型转换

LocalDate   toLocalDate()
LocalDateTime   toLocalDateTime()
LocalTime   toLocalTime()
OffsetDateTime  toOffsetDateTime()
ZonedDateTime   truncatedTo(TemporalUnit unit)

4、对象信息获取

int get(TemporalField field)
int getDayOfMonth()
int getDayOfYear()
int getHour()
long    getLong(TemporalField field)
int getMinute()
Month   getMonth()
int getMonthValue()
int getNano()
int getSecond()
int getYear()
ZoneId  getZone()
ZoneOffset  getOffset()
DayOfWeek   getDayOfWeek()

5、格式化

String  format(DateTimeFormatter formatter)

6、时间距离

long    until(Temporal endExclusive, TemporalUnit unit)

7、对象信息判断

boolean isSupported(TemporalField field)
boolean isSupported(TemporalUnit unit)

8、其他方法

<R> R   query(TemporalQuery<R> query)
ValueRange  range(TemporalField field)

三、OffsetDateTime

1、静态方法,获取对象

static OffsetDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset)
static OffsetDateTime of(LocalDate date, LocalTime time, ZoneOffset offset)
static OffsetDateTime of(LocalDateTime dateTime, ZoneOffset offset)
static OffsetDateTime ofInstant(Instant instant, ZoneId zone)static OffsetDateTime now()
static OffsetDateTime now(Clock clock
static OffsetDateTime now(ZoneId zone)static OffsetDateTime parse(CharSequence text)
static OffsetDateTime parse(CharSequence text, DateTimeFormatter formatter)static OffsetDateTime from(TemporalAccessor temporal

2、格式化

String format(DateTimeFormatter formatter)

3、获取对象信息

int get(TemporalField field)
int getDayOfMonth()
DayOfWeek getDayOfWeek()
int getDayOfYear()
int getHour()
long getLong(TemporalField field)
int getMinute()
Month getMonth()
int getMonthValue()
int getNano()
ZoneOffset getOffset()
int getSecond()
int getYear()

4、对象判断

boolean isAfter(OffsetDateTime other)
boolean isBefore(OffsetDateTime other)
boolean isEqual(OffsetDateTime other)
boolean isSupported(TemporalField field)
boolean isSupported(TemporalUnit unit)

5、对象计算

//加
OffsetDateTime plus(long amountToAdd, TemporalUnit unit)
OffsetDateTime plus(TemporalAmount amountToAdd)
OffsetDateTime plusDays(long days)
OffsetDateTime plusHours(long hours)
OffsetDateTime plusMinutes(long minutes)
OffsetDateTime plusMonths(long months)
OffsetDateTime plusNanos(long nanos)
OffsetDateTime plusSeconds(long seconds)
OffsetDateTime plusWeeks(long weeks)
OffsetDateTime plusYears(long years)//减
OffsetDateTime minus(long amountToSubtract, TemporalUnit unit)
OffsetDateTime minus(TemporalAmount amountToSubtract)
OffsetDateTime minusDays(long days)
OffsetDateTime minusHours(long hours)
OffsetDateTime minusMinutes(long minutes)
OffsetDateTime minusMonths(long months)
OffsetDateTime minusNanos(long nanos)
OffsetDateTime minusSeconds(long seconds)
OffsetDateTime minusWeeks(long weeks)
OffsetDateTime minusYears(long years)//自定义
OffsetDateTime with(TemporalAdjuster adjuster)
OffsetDateTime with(TemporalField field, long newValue)
OffsetDateTime withDayOfMonth(int dayOfMonth)
OffsetDateTime withDayOfYear(int dayOfYear)
OffsetDateTime withHour(int hour)
OffsetDateTime withMinute(int minute)
OffsetDateTime withMonth(int month)
OffsetDateTime withNano(int nanoOfSecond)
OffsetDateTime withOffsetSameInstant(ZoneOffset offset)
OffsetDateTime withOffsetSameLocal(ZoneOffset offset)
OffsetDateTime withSecond(int second)
OffsetDateTime withYear(int year)

6、对象改变

Instant toInstant()
LocalDate toLocalDate()
LocalDateTime toLocalDateTime()
LocalTime toLocalTime()
OffsetTime toOffsetTime()
ZonedDateTime toZonedDateTime()

7、对象统计

long toEpochSecond()//将此日期时间的秒数从1970-01-01t00:00:00z时代

8、对象改变

Temporal adjustInto(Temporal temporal)
ZonedDateTime atZoneSameInstant(ZoneId zone)
ZonedDateTime atZoneSimilarLocal(ZoneId zone)

9、时间距离

long until(Temporal endExclusive, TemporalUnit unit)

10、其他方法

<R> R query(TemporalQuery<R> query)
static Comparator<OffsetDateTime> timeLineOrder()
ValueRange range(TemporalField field)

四、OffsetTime

1、静态方法。获取对象

static OffsetTime of(int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset)
static OffsetTime of(LocalTime time, ZoneOffset offset)
static OffsetTime ofInstant(Instant instant, ZoneId zone)static OffsetTime now()
static OffsetTime now(Clock clock)
static OffsetTime now(ZoneId zone)static OffsetTime from(TemporalAccessor temporal)static OffsetTime parse(CharSequence text)
static OffsetTime parse(CharSequence text, DateTimeFormatter formatter)

2、对象格式化

String format(DateTimeFormatter formatter)

3、对象信息获取

int get(TemporalField field)
int getHour()
long getLong(TemporalField field)
int getMinute()
int getNano()
ZoneOffset getOffset()
int getSecond()

4、对象信息判断

boolean isAfter(OffsetTime other)
boolean isBefore(OffsetTime other)
boolean isEqual(OffsetTime other)
boolean isSupported(TemporalField field)
boolean isSupported(TemporalUnit unit)

5、对象计算

//加
OffsetTime plus(long amountToAdd, TemporalUnit unit)
OffsetTime plus(TemporalAmount amountToAdd)
OffsetTime plusHours(long hours)
OffsetTime plusMinutes(long minutes)
OffsetTime plusNanos(long nanos)
OffsetTime plusSeconds(long seconds)//减
OffsetTime minus(long amountToSubtract, TemporalUnit unit)
OffsetTime minus(TemporalAmount amountToSubtract)
OffsetTime minusHours(long hours)
OffsetTime minusMinutes(long minutes)
OffsetTime minusNanos(long nanos)
OffsetTime minusSeconds(long seconds)//自定义
OffsetTime with(TemporalAdjuster adjuster)
OffsetTime with(TemporalField field, long newValue)
OffsetTime withHour(int hour)
OffsetTime withMinute(int minute)
OffsetTime withNano(int nanoOfSecond)
OffsetTime withOffsetSameInstant(ZoneOffset offset)
OffsetTime withOffsetSameLocal(ZoneOffset offset)
OffsetTime withSecond(int second)

6、时间距离

long until(Temporal endExclusive, TemporalUnit unit)

7、对象改变

LocalTime toLocalTime()
Temporal adjustInto(Temporal temporal)
OffsetDateTime atDate(LocalDate date)

8、其他方法

<R> R query(TemporalQuery<R> query)
ValueRange range(TemporalField field)

java时区时间ZoneOffset, ZoneId,OffsetTime,OffsetDateTime,ZonedDateTime相关推荐

  1. java 日本时区_java时区时间ZoneOffset, ZoneId,OffsetTime,OffsetDateTi

    前言 ZoneOffset,LocalDateTime,LocalTime, YearMonth, Year, MonthDay,它们代表与上下文相结合的本地日期/时间.这些类主要用于不需要在上下文中 ...

  2. 【Java 8 新特性】Java 8 时间接口示例:MonthDay、Month、OffsetDateTime 和 OffsetTime

    Java 8 时间接口示例:MonthDay.Month.OffsetDateTime 和 OffsetTime java.time.MonthDay java.time.Month java.tim ...

  3. java zone_offset_java 的 ZoneOffset 与 ZoneId

    关于时区常见的问题:如何在java8及更高版本中获取默认的ZoneOffset? tl;dr OffsetDateTime.now().getOffset() 但是,建议使用时区(ZoneId) 而不 ...

  4. 带时区时间日期 ZonedDateTime

    带时区时间日期 ZonedDateTime 1. 简介 ZonedDateTime表示带时区的日期时间,如2007-12-03T10:15:30+01:00 Europe/Paris. 参考官方文档描 ...

  5. Java获取当前时区时间LocalDateTime与System.currentTimeMillis

    Java获取当前时区时间 System.currentTimeMillis LocalDateTime 最终结果 全球根据纬度不同,划分不同的时区.对于此时此刻,大家同处同一个时间点,但是,每个时区的 ...

  6. java不同时区时间转换,Java不同时区(timezone)之间时间转换

    最近出现一个问题是这样的 我们的系统在国外打印的日志时间由于时差关系和国内不一致 看起来不方便 希望国外的日志和国内保持一致 即 需要对不同时区的时间做转换调整 统一为国内时间. 一.关于时区的一些概 ...

  7. java 不同时区时间转换_Java对世界不同时区timezone之间时间转换的处理方法

    最近出现一个问题是这样的:我们的系统在国外打印的日志时间由于时差关系和国内不一致,看起来不方便,希望国外的日志和国内保持一致,即:需要对不同时区的时间做转换调整,统一为国内时间. 一.关于时区的一些概 ...

  8. 一文告诉你Java日期时间API到底有多烂

    前言 你好,我是A哥(YourBatman). 好看的代码,千篇一律!难看的代码,卧槽卧槽~其实没有什么代码是"史上最烂"的,要有也只有"史上更烂". 日期是商 ...

  9. java 时区处理_如何使用Java处理日历时区?

    如何使用Java处理日历时区? 我有一个来自我的应用程序的Timestamp值. 用户可以在任何给定的本地TimeZone中. 由于此日期用于假定给定时间始终为GMT的WebService,因此我需要 ...

最新文章

  1. apache禁止访问html,apache 限制目录访问
  2. 通过form表单请求servlet资源代码
  3. HDU4539+状态压缩DP
  4. Mysql数据库(五)——mysql事务及引擎
  5. container 的背后
  6. ubuntu meld比较文件差异
  7. zookeeper版本更新_zookeeper介绍及运维实践
  8. 如何在SQL Server 2016中使用R合并和拆分CSV文件
  9. 传奇脚本中提到的WIL序号是什么?在哪查看WIL序号?
  10. Set集合练习题02
  11. 苹果cms V10 七色中文 二开苹果cms视频 图片 小说网站源码模板
  12. java ipv6 转换_Java中Ipv4与Ipv6的转换
  13. 系统集成项目管理工程师(中级)考试心得经验
  14. python selenium清除缓存_SeleniumPython:无法清除chrome浏览器缓存
  15. uni-app云打包 No enum constant com.pandora.pack.core.PackagePlatform.ANDROID_CLC
  16. 怎么为PE添加输入法
  17. activeMQ启动失败报错illegal character in hostname at index
  18. 分享一种高效伪随机数生成算法
  19. 单播、广播、多播(组播)的概念和区别
  20. C++ 超详细8Bit图像直方图统计并绘制显示,不使用calcHist()函数,自己手写统计

热门文章

  1. 不可思议有氧机器人_不思议迷宫奇怪的机器人怎么得?不思议迷宫奇怪的机器人获取一览...
  2. 常见程序(discuz,ecshop,shopex,dedecms等)重置破解管理密码
  3. Python 爬虫心得
  4. 微信小程序上传图像或者文件到阿里云oss
  5. 转 鲁迅《随感录》之一二
  6. 除了打工上班,为什么普通人很难长时间坚持去做一件事?
  7. java 九九乘法口诀
  8. 人工智能/数据科学比赛汇总 2019.6
  9. JS-WebAPI练习
  10. Dubbo comsumer 远程调用流程分析