前言

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   query(TemporalQuery 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 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   query(TemporalQuery 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 query(TemporalQuery query)

static Comparator 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 query(TemporalQuery query)

ValueRange range(TemporalField field)

java 日本时区_java时区时间ZoneOffset, ZoneId,OffsetTime,OffsetDateTi相关推荐

  1. java时区时间ZoneOffset, ZoneId,OffsetTime,OffsetDateTime,ZonedDateTime

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

  2. java时区_Java时区

    java时区 Java TimeZone class represents a time zone offset, and also figures out daylight savings. Tim ...

  3. java date类 时区_Java时区转换及Date类实现原理解析

    这篇文章主要介绍了Java时区转换及Date类实现原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 一.时区的说明 地球表面按经线从东到西,被 ...

  4. 东八区转为0时区_Java时区转换及时间格式

    本文介绍Java API 中 Date, Calendar, TimeZone和DateFormat的使用,以及不同时区时间相互转化的方法和原理. 问题描述: 向处于不同时区的服务器发请求时需要考虑时 ...

  5. java 转时区_java – 时区转换

    一些例子 import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; publi ...

  6. java 8小时_Java获取时间与系统时间相差8小时终极解决方案

    0.引言 Druid中时区的问题一直困扰着我们,所以我专门去研究了一下世界时区和Java中的时区,对使用Druid很用帮助. 1.UTC时间&GMT时间 UTC时间是时间标准时间(Univer ...

  7. java数组顺序_Java – 按时间排序数组

    这里的其他答案很好,但使用过时的类. java.time 在Java 8及更高版本中,我们现在内置了java.time框架(带有Java 6& 7和Android的后端口).与旧的日期时间类相 ...

  8. java换算当地时间_Java UTC时间与本地时间互相转换

    协调世界时,又称世界统一时间.世界标准时间.国际协调时间.由于英文(CUT)和法文(TUC)的缩写不同,作为妥协,简称UTC. 这套时间系统被应用于许多互联网和万维网的标准中,例如,网络时间协议就是协 ...

  9. java 加日期_java 给时间增加时间得到一个新的时间(日期)

    SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd") LocalDate expirationDate String exp ...

最新文章

  1. R语言文摘:Subsetting Data
  2. 大数据入门级学习路线
  3. anki 插入表格_anki|建造师选择题制作的方法
  4. 67.数据库系统的三级模式
  5. Java并发编程实战_福州java编程实战培训班排名
  6. 中台是个筐,啥都往里装?
  7. 对比关系生成模型(Comparative Relation Generative Model)
  8. docker安装rabbitmq及简单管理
  9. mfc动态改变clip风格_echarts动态滑动平均滤波
  10. [其他] 10种技巧可提升Android应用运行效果
  11. 0010-伪类选择器-前端学习笔记
  12. switchHost管理员身份运行出错问题
  13. python快速实现简易贪吃蛇小游戏
  14. CFI Flash, JEDEC Flash ,Parellel Flash, SPI Flash, Nand Flash,Nor Flash的区别和联系
  15. FRM 5.3业绩衡量比率
  16. 【tomcat运行异常】Error running ‘*** [org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run]‘
  17. 追踪货拉拉:“亡羊补牢”进度缓慢,安全“地雷”何时能拆完?
  18. 关于Windows文件读写(提高读写速度)
  19. Tiny 4412 lcd 驱动分析
  20. 迪赛智慧数——柱状图(基本柱状图):1994-2022年历届世界杯投入资金

热门文章

  1. 【Http】PKIX(PKIX path building failed) 问题 unable to find valid certification path to requested target
  2. VM : 虚拟机中Linux磁盘的挂载与卸载
  3. 95-190-454-源码-window-Trigger-Flink 自定义trigger
  4. 【java】java基础之SPI框架实现-整体设计
  5. Error:Unable to make the module: core, related gradle configuration was not found. Please, re-import
  6. scala学习-Linux命令行运行jar包传入main方法参数
  7. Java web 中的 三层架构
  8. 修改 Docker 的镜像存储位置
  9. 为什么redis可以做分布式锁
  10. 阿里取消“361”绩效考核,不写周报不鼓励加班?