public final class OffsetDateTime extends Object implements Temporal, TemporalAdjuster, Comparable<OffsetDateTime>, Serializable
2007-12-03T10:15:30+01:00。
OffsetDateTime与偏移日期时间不变的表示。这类商店所有的日期和时间字段,一个精确的时间,以及从UTC偏移/格林尼治。例如,值“2007年10月2日在13: 45.30.123456789 +日期”可以存储在一个OffsetDateTime。
OffsetDateTime,ZonedDateTime和Instant所有存储在时间线上即时纳秒的精度。Instant是最简单的,简单的代表瞬间。OffsetDateTime添加到即时从UTC /格林尼治的偏移,使得本地日期时间得到。ZonedDateTime加全时区规则。
它的目的是,ZonedDateTime或Instant用于简单的应用模型数据。此类可以在更详细的建模日期时间概念时使用,或与数据库或网络协议进行通信时使用。
这是一个value-based类;利用身份敏感的操作(包括引用相等(==),身份的哈希代码,或同步)的实例OffsetDateTime可能有不可预知的结果应该是可以避免的。的equals法进行比较。
| Modifier and Type | Field and Description |
|---|---|
static OffsetDateTime |
MAX
所支持的最大
OffsetDateTime,+999999999,999999999 -12-31t23:59:59. -18:00”。
|
static OffsetDateTime |
MIN
最小支持
OffsetDateTime,' 999999999 ' -01-01t00:00:00 + 18:00。
|
| Modifier and Type | Method and Description |
|---|---|
Temporal |
adjustInto(Temporal temporal)
调整指定的时间对象以具有相同的偏移量、日期和时间为对象。
|
ZonedDateTime |
atZoneSameInstant(ZoneId zone)
结合时间与时区来创建一个
ZonedDateTime确保结果具有相同的瞬间。
|
ZonedDateTime |
atZoneSimilarLocal(ZoneId zone)
结合时间与时区来创建一个
ZonedDateTime一直保持相同的本地日期和时间。
|
int |
compareTo(OffsetDateTime other)
比较这
OffsetDateTime到另一个日期时间。
|
boolean |
equals(Object obj)
检查此日期时间是否等于另一个日期时间。
|
String |
format(DateTimeFormatter formatter)
这个日期时间格式使用指定的格式化程序。
|
static OffsetDateTime |
from(TemporalAccessor temporal)
获得
OffsetDateTime实例从一个时空对象。
|
int |
get(TemporalField field)
从这个日期时间作为一个
int获取指定字段的值。
|
int |
getDayOfMonth()
获取月字段的一天。
|
DayOfWeek |
getDayOfWeek()
获取星期域,这是一个枚举
DayOfWeek。
|
int |
getDayOfYear()
获取一年的日子。
|
int |
getHour()
获取天字段的时间。
|
long |
getLong(TemporalField field)
从这个日期时间为
long获取指定字段的值。
|
int |
getMinute()
获取小时字段的分钟。
|
Month |
getMonth()
得到月年田间使用
Month枚举。
|
int |
getMonthValue()
从1到12得到一个月的时间字段。
|
int |
getNano()
获取第二场的纳米。
|
ZoneOffset |
getOffset()
能带偏移,如“+”01:00。
|
int |
getSecond()
获取第二个分钟字段。
|
int |
getYear()
获取年度字段。
|
int |
hashCode()
用于此日期时间的哈希代码。
|
boolean |
isAfter(OffsetDateTime other)
检查此日期时间的即时是否在指定日期时间之后。
|
boolean |
isBefore(OffsetDateTime other)
检查此日期时间的即时是否在指定日期时间之前。
|
boolean |
isEqual(OffsetDateTime other)
检查此日期时间的即时是否等于指定日期时间的时间。
|
boolean |
isSupported(TemporalField field)
检查指定字段是否被支持。
|
boolean |
isSupported(TemporalUnit unit)
检查指定的单位是否被支持。
|
OffsetDateTime |
minus(long amountToSubtract, TemporalUnit unit)
返回此日期时间的副本,用指定的金额减去。
|
OffsetDateTime |
minus(TemporalAmount amountToSubtract)
返回此日期时间的副本,用指定的金额减去。
|
OffsetDateTime |
minusDays(long days)
返回一份本
OffsetDateTime与指定的期间天数减去。
|
OffsetDateTime |
minusHours(long hours)
返回一份本
OffsetDateTime减去指定的时间在小时。
|
OffsetDateTime |
minusMinutes(long minutes)
返回一份本
OffsetDateTime在几分钟之内减去指定的时间。
|
OffsetDateTime |
minusMonths(long months)
返回一份本
OffsetDateTime与指定期个月减去。
|
OffsetDateTime |
minusNanos(long nanos)
返回一份本
OffsetDateTime减去指定的时间在纳秒。
|
OffsetDateTime |
minusSeconds(long seconds)
返回一份本
OffsetDateTime与指定期秒减去。
|
OffsetDateTime |
minusWeeks(long weeks)
返回一份本
OffsetDateTime在周中减去指定的时间。
|
OffsetDateTime |
minusYears(long years)
返回一份本
OffsetDateTime与指定期在年中减去。
|
static OffsetDateTime |
now()
从默认时区中的系统时钟中获取当前日期时间。
|
static OffsetDateTime |
now(Clock clock)
从指定的时钟中获取当前日期时间。
|
static OffsetDateTime |
now(ZoneId zone)
从指定时区中的系统时钟中获得当前日期时间。
|
static OffsetDateTime |
of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset)
获得
OffsetDateTime实例从年,月,日,小时,分钟,秒,纳秒和偏移。
|
static OffsetDateTime |
of(LocalDate date, LocalTime time, ZoneOffset offset)
获得
OffsetDateTime实例从一个日期,时间和偏移。
|
static OffsetDateTime |
of(LocalDateTime dateTime, ZoneOffset offset)
从一个日期时间得到
OffsetDateTime实例和偏移。
|
static OffsetDateTime |
ofInstant(Instant instant, ZoneId zone)
获得
OffsetDateTime实例从一个
Instant和区域ID。
|
static OffsetDateTime |
parse(CharSequence text)
获得
OffsetDateTime实例从一个文本字符串,如
2007-12-03T10:15:30+01:00。
|
static OffsetDateTime |
parse(CharSequence text, DateTimeFormatter formatter)
获得
OffsetDateTime实例从使用特定格式的文本字符串。
|
OffsetDateTime |
plus(long amountToAdd, TemporalUnit unit)
返回此日期时间的副本,添加指定的金额。
|
OffsetDateTime |
plus(TemporalAmount amountToAdd)
返回此日期时间的副本,添加指定的金额。
|
OffsetDateTime |
plusDays(long days)
返回一份本offsetdatetime在天期间添加指定的。
|
OffsetDateTime |
plusHours(long hours)
返回一份本
OffsetDateTime在指定时间内添加时间。
|
OffsetDateTime |
plusMinutes(long minutes)
返回一份本
OffsetDateTime在几分钟之内指定期间补充。
|
OffsetDateTime |
plusMonths(long months)
返回一份本
OffsetDateTime在月期添加指定的。
|
OffsetDateTime |
plusNanos(long nanos)
返回一份本
OffsetDateTime在纳秒指定期间补充。
|
OffsetDateTime |
plusSeconds(long seconds)
返回一份本
OffsetDateTime在指定时间内增加秒。
|
OffsetDateTime |
plusWeeks(long weeks)
返回一份本offsetdatetime在周指定期间补充。
|
OffsetDateTime |
plusYears(long years)
返回一份本
OffsetDateTime年指定期间补充。
|
<R> R |
query(TemporalQuery<R> query)
使用指定的查询查询此日期时间。
|
ValueRange |
range(TemporalField field)
获取指定字段的有效值的范围。
|
static Comparator<OffsetDateTime> |
timeLineOrder()
获取一个比较器,比较基于即时两
OffsetDateTime实例。
|
long |
toEpochSecond()
将此日期时间的秒数从1970-01-01t00:00:00z时代。
|
Instant |
toInstant()
将这一
Instant日期时间。
|
LocalDate |
toLocalDate()
获取此日期时间的
LocalDate部分。
|
LocalDateTime |
toLocalDateTime()
获取此偏移时间的
LocalDateTime部分。
|
LocalTime |
toLocalTime()
获取此日期时间的
LocalTime部分。
|
OffsetTime |
toOffsetTime()
将这一
OffsetTime日期时间。
|
String |
toString()
输出该日期时间为
String,如
2007-12-03T10:15:30+01:00。
|
ZonedDateTime |
toZonedDateTime()
将这一日期时间
ZonedDateTime使用偏移的区域ID。
|
OffsetDateTime |
truncatedTo(TemporalUnit unit)
返回一份本
OffsetDateTime与定时。
|
long |
until(Temporal endExclusive, TemporalUnit unit)
计算时间的量,直到指定单元的另一个日期时间。
|
OffsetDateTime |
with(TemporalAdjuster adjuster)
返回此日期时间的调整副本。
|
OffsetDateTime |
with(TemporalField field, long newValue)
将此日期时间的副本与指定的字段设置为一个新值。
|
OffsetDateTime |
withDayOfMonth(int dayOfMonth)
返回一份本
OffsetDateTime与月改变的一天。
|
OffsetDateTime |
withDayOfYear(int dayOfYear)
返回一份本
OffsetDateTime与天的年变化。
|
OffsetDateTime |
withHour(int hour)
返回一份本
OffsetDateTime与一个值改变。
|
OffsetDateTime |
withMinute(int minute)
返回一份本
OffsetDateTime与分钟小时值改变。
|
OffsetDateTime |
withMonth(int month)
返回一份本
OffsetDateTime与月的年变化。
|
OffsetDateTime |
withNano(int nanoOfSecond)
返回一份本
OffsetDateTime与纳米二值改变。
|
OffsetDateTime |
withOffsetSameInstant(ZoneOffset offset)
返回一份本
OffsetDateTime与指定的偏移量确保结果是在同一瞬间。
|
OffsetDateTime |
withOffsetSameLocal(ZoneOffset offset)
返回一份本
OffsetDateTime与指定的偏移量确保结果具有相同的本地日期时间。
|
OffsetDateTime |
withSecond(int second)
返回一份本
OffsetDateTime第二分钟值改变。
|
OffsetDateTime |
withYear(int year)
返回一份本
OffsetDateTime与年变化。
|
public static final OffsetDateTime MIN
OffsetDateTime,' 999999999 ' -01-01t00:00:00 + 18:00。这是午夜的本地日期时间在最大偏移量的最小日期开始(较大的偏移量是较早的时间线)。这将
LocalDateTime.MIN和
ZoneOffset.MAX。这可以被一个应用程序作为一个“遥远的过去”日期时间。
public static final OffsetDateTime MAX
OffsetDateTime,+999999999,999999999 -12-31t23:59:59. -18:00”。这是本地日期时间,在午夜结束时的最大日期在最小偏移量(较大的负偏移量是后来的时间线)。这将
LocalDateTime.MAX和
ZoneOffset.MIN。这可以被一个应用程序作为一个“遥远的未来”日期时间。
public static Comparator<OffsetDateTime> timeLineOrder()
OffsetDateTime实例。
这种方法不同于在compareTo(java.time.OffsetDateTime)在比较,只是比较底层的瞬间。
isAfter(java.time.OffsetDateTime),
isBefore(java.time.OffsetDateTime),
isEqual(java.time.OffsetDateTime)
public static OffsetDateTime now()
这将查询system clock在默认时区获取当前日期时间。偏移量将从时钟的时区计算。
使用这种方法将防止使用另一个时钟进行测试的能力,因为时钟是硬编码的。
public static OffsetDateTime now(ZoneId zone)
这将查询system clock获得当前的日期时间。指定时区避免依赖于默认时区。偏移量将从指定的时区计算出来。
使用这种方法将防止使用另一个时钟进行测试的能力,因为时钟是硬编码的。
zone -区ID使用,不为空
public static OffsetDateTime now(Clock clock)
这将查询指定的时钟,以获得当前日期时间。偏移量将从时钟的时区计算。
使用这种方法允许使用一个备用时钟进行测试。备用时钟可采用dependency injection。
clock -时钟使用,不为空
public static OffsetDateTime of(LocalDate date, LocalTime time, ZoneOffset offset)
OffsetDateTime实例从一个日期,时间和偏移。
这将创建一个偏移日期时间与指定的本地日期、时间和偏移量。
date -本地日期,不为空
time -当地时间,不空
offset -区偏移,不空
public static OffsetDateTime of(LocalDateTime dateTime, ZoneOffset offset)
OffsetDateTime实例和偏移。
这将创建一个偏移日期时间与指定的本地日期时间和偏移量。
dateTime -本地日期时间,不空
offset -区偏移,不空
public static OffsetDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset)
OffsetDateTime实例从年,月,日,小时,分钟,秒,纳秒和偏移。
这将创建一个偏移日期时间与七个指定的字段。
这种方法主要存在于编写测试用例的情况下。非测试代码通常会使用其他方法来创建一个偏移时间。LocalDateTime有五额外的便利以减少参数等效工厂方法的变种。他们没有在这里提供减少的足迹的原料药。
year年的代表,从min_year到max_year
month -年月为代表,从1(一月)到12(十二月)
dayOfMonth -月代表天,从1到31
hour -天代表小时,从0到23
minute -小时代表分钟,从0到59
second -二分为代表,从0到59
nanoOfSecond -二代表纳米,从0到999999999
offset区偏移,不空
DateTimeException -如果任何字段的值超出范围,或如果月日年月日是无效的
public static OffsetDateTime ofInstant(Instant instant, ZoneId zone)
OffsetDateTime实例从一个
Instant和
这将创建一个与指定的相同时刻的偏移日期时间。发现从UTC /格林尼治偏简单有每个时刻只有一个有效的抵消。
区ID。instant -创建日期时间的瞬间,不为空
zone的时区,这可能是一个偏移量,不为空
DateTimeException -如果结果超过支持的范围
public static OffsetDateTime from(TemporalAccessor temporal)
OffsetDateTime实例从一个时空对象。
这将获得一个基于指定时间的偏移日期时间。一个TemporalAccessor表示日期和时间信息,任意设置,本厂将以OffsetDateTime实例。
转换将首先从时态对象获得ZoneOffset。然后它会试图获得一个LocalDateTime,回落到一个Instant如果必要。其结果将是ZoneOffset带LocalDateTime或Instant组合。实现允许执行优化,如访问这些字段,这些字段相当于相关对象。
这种方法相匹配的功能接口TemporalQuery可以通过方法引用查询中的签名,OffsetDateTime::from。
temporal -转换时间的对象,不为空
DateTimeException如果无法转换到一个
OffsetDateTime
public static OffsetDateTime parse(CharSequence text)
OffsetDateTime实例从一个文本字符串,如
2007-12-03T10:15:30+01:00。
该字符串必须是一个有效的日期时间和使用DateTimeFormatter.ISO_OFFSET_DATE_TIME解析。
text -解析如“2007-12-03t10:15:30 + 01:00”文本,不空
DateTimeParseException如果文本不能解析
public static OffsetDateTime parse(CharSequence text, DateTimeFormatter formatter)
OffsetDateTime实例从使用特定格式的文本字符串。
文字使用格式化程序解析,返回一个日期时间。
text -解析文本,不空
formatter -格式化程序使用,不为空
DateTimeParseException如果文本不能解析
public boolean isSupported(TemporalField field)
此检查如果此日期时间可以查询指定的字段。如果为false,则调用range,get和with(TemporalField, long)方法将抛出一个异常。
如果该字段是ChronoField然后查询执行。支持的字段是:
NANO_OF_SECONDNANO_OF_DAYMICRO_OF_SECONDMICRO_OF_DAYMILLI_OF_SECONDMILLI_OF_DAYSECOND_OF_MINUTESECOND_OF_DAYMINUTE_OF_HOURMINUTE_OF_DAYHOUR_OF_AMPMCLOCK_HOUR_OF_AMPMHOUR_OF_DAYCLOCK_HOUR_OF_DAYAMPM_OF_DAYDAY_OF_WEEKALIGNED_DAY_OF_WEEK_IN_MONTHALIGNED_DAY_OF_WEEK_IN_YEARDAY_OF_MONTHDAY_OF_YEAREPOCH_DAYALIGNED_WEEK_OF_MONTHALIGNED_WEEK_OF_YEARMONTH_OF_YEARPROLEPTIC_MONTHYEAR_OF_ERAYEARERAINSTANT_SECONDSOFFSET_SECONDSChronoField实例将返回false。
如果该字段是不是ChronoField,然后通过调用作为参数传递this TemporalField.isSupportedBy(TemporalAccessor)得到此方法的结果。是否支持字段由字段确定。
isSupported 接口
TemporalAccessor
field -现场检查null返回false
public boolean isSupported(TemporalUnit unit)
此检查如果指定的单位可以添加到或减去,这个日期时间。如果为false,则调用plus(long, TemporalUnit)和minus方法将抛出一个异常。
如果单位是一个ChronoUnit然后查询执行。所支持的单位是:
NANOSMICROSMILLISSECONDSMINUTESHOURSHALF_DAYSDAYSWEEKSMONTHSYEARSDECADESCENTURIESMILLENNIAERASChronoUnit实例将返回false。
如果单位不ChronoUnit,然后通过调用作为参数传递this TemporalUnit.isSupportedBy(Temporal)得到此方法的结果。是否支持单位是由单位确定的。
isSupported 接口
Temporal
unit -检查单元,空返回false
public ValueRange range(TemporalField field)
该范围对象表示字段的最小值和最大有效值。此日期时间用于提高返回范围的准确性。如果它是不可能返回的范围,因为字段不支持或其他一些原因,抛出一个异常。
如果该字段是ChronoField然后查询执行。的supported fields将返回适当的范围的情况下。所有其他ChronoField实例将抛出一个UnsupportedTemporalTypeException。
如果该字段是不是ChronoField,然后通过调用作为参数传递this TemporalField.rangeRefinedBy(TemporalAccessor)得到此方法的结果。是否可以得到范围是由字段确定的。
range 接口
TemporalAccessor
field -现场查询范围,不为空
DateTimeException如果不能得到的领域范围
UnsupportedTemporalTypeException如果字段不支持
public int get(TemporalField field)
int获取指定字段的值。
此查询此日期时间为指定字段的值。返回的值将始终在字段的有效值范围内。如果不可能返回值,因为字段不支持或其他原因,则抛出异常。
如果该字段是ChronoField然后查询执行。的supported fields将基于此日期时间、有效值除NANO_OF_DAY,MICRO_OF_DAY,EPOCH_DAY,PROLEPTIC_MONTH和INSTANT_SECONDS太大,安装在一个int、扔DateTimeException。所有其他ChronoField实例将抛出一个UnsupportedTemporalTypeException。
如果该字段是不是ChronoField,然后通过调用作为参数传递this TemporalField.getFrom(TemporalAccessor)得到此方法的结果。是否可以得到值,以及值表示的值,由字段确定。
get 接口
TemporalAccessor
field -领域有,不空
DateTimeException如果字段的值是不能获得或值不在字段的有效值范围内
UnsupportedTemporalTypeException -如果字段不支持或值的范围超过一个
int
ArithmeticException如果数值溢出时
public long getLong(TemporalField field)
long获取指定字段的值。
此查询此日期时间为指定字段的值。如果不可能返回值,因为字段不支持或其他原因,则抛出异常。
如果该字段是ChronoField然后查询执行。的supported fields将基于此日期时间的有效值。所有其他ChronoField实例将抛出一个UnsupportedTemporalTypeException。
如果该字段是不是ChronoField,然后通过调用作为参数传递this TemporalField.getFrom(TemporalAccessor)得到此方法的结果。是否可以得到值,以及值表示的值,由字段确定。
getLong 接口
TemporalAccessor
field -领域有,不空
DateTimeException如果不能得到一个价值领域
UnsupportedTemporalTypeException如果字段不支持
ArithmeticException如果数值溢出时
public ZoneOffset getOffset()
这是从UTC /格林尼治本地时间偏移。
public OffsetDateTime withOffsetSameLocal(ZoneOffset offset)
OffsetDateTime与指定的偏移量确保结果具有相同的本地日期时间。
此方法返回具有相同的LocalDateTime和指定的ZoneOffset对象。不需计算或执行。例如,如果这个时候代表2007-12-03T10:30+02:00和偏移指定+03:00,此方法将返回2007-12-03T10:30+03:00。
考虑到之间的偏移量的差异,以及时间方面的调整,使用withOffsetSameInstant(java.time.ZoneOffset)。
此实例是不可变的,不受此方法调用的影响。
offset -带偏移改变,不为空
OffsetDateTime,不空
public OffsetDateTime withOffsetSameInstant(ZoneOffset offset)
OffsetDateTime与指定的偏移量确保结果是在同一瞬间。
此方法返回与指定的ZoneOffset和LocalDateTime由两个偏移量之间的差异调整对象。这将导致在旧的和新的对象表示相同的即时。这是有用的,寻找当地时间在一个不同的偏移。例如,如果这个时候代表2007-12-03T10:30+02:00和偏移指定+03:00,此方法将返回2007-12-03T11:30+03:00。
改变偏移没有调整本地时间使用withOffsetSameLocal(java.time.ZoneOffset)。
此实例是不可变的,不受此方法调用的影响。
offset -带偏移改变,不为空
OffsetDateTime,不空
DateTimeException -如果结果超过支持的日期范围
public LocalDateTime toLocalDateTime()
LocalDateTime部分。
这将返回一个具有相同的年、月LocalDateTime,日期和时间日期时间。
public LocalDate toLocalDate()
LocalDate部分。
这将返回一个与当年LocalDate,月日这个日期时间。
public int getYear()
此方法将返回该年原始int价值。
此方法返回的一年预期为每get(YEAR)。获得时代的一年,用get(YEAR_OF_ERA)。
public int getMonthValue()
这个方法返回月作为一个int从1到12。应用程序代码经常清楚如果枚举Month是通过调用getMonth()使用。
getMonth()
public Month getMonth()
getMonthValue()
public int getDayOfMonth()
此方法返回月天原始int价值。
public int getDayOfYear()
此方法返回的年日的原始int价值。
public DayOfWeek getDayOfWeek()
DayOfWeek。
此方法返回的枚举DayOfWeek星期。这避免了混乱是什么int平均值。如果你需要访问原始int值然后枚举提供int value。
更多的信息可以从DayOfWeek获得。这包括值的文本名称。
public LocalTime toLocalTime()
LocalTime部分。
这将返回一个具有相同的小时,分钟LocalTime,二和纳秒这个日期时间。
public int getHour()
public int getMinute()
public int getSecond()
public int getNano()
public OffsetDateTime with(TemporalAdjuster adjuster)
这将返回一个OffsetDateTime,基于此,与日期时间调整。调整使用指定的调整器策略对象。阅读调整器的文档,了解将要做什么调整。
一个简单的调节器可以简单地设置一个字段,例如年字段。一个更复杂的调节器可能会把日期定在月的最后一天。选择常见的调整提供了TemporalAdjuster。这些措施包括寻找“月的最后一天”和“下星期三”。关键日期时间类也实现TemporalAdjuster接口,如Month和MonthDay。该调节器是负责处理特殊情况下,如不同长度的月和跳跃年。
例如,此代码在七月的最后一天返回日期:
进口静态java。时间。月。*;进口静态java。时间。时间。调节。*;结果:offsetdatetime,(七月),(lastdayofmonth());
这类LocalDate,LocalTime和ZoneOffset实施TemporalAdjuster,因此该方法可用于更改日期、时间或偏移:
结果:offsetdatetime与(日期);结果:offsetdatetime与(时间);结果:offsetdatetime。与(偏移);
这种方法的结果是通过调用指定的调节器,通过this作为论据的TemporalAdjuster.adjustInto(Temporal)方法得到的。
此实例是不可变的,不受此方法调用的影响。
with 接口
Temporal
adjuster -调节器使用,不为空
this一
OffsetDateTime,不空
DateTimeException -如果调整不能
ArithmeticException如果数值溢出时
public OffsetDateTime with(TemporalField field, long newValue)
这将返回一个OffsetDateTime,在此基础上,对指定字段的值的变化。这可以用来改变任何支持的领域,如一年,一个月或一天的月。如果不可能设置值,因为字段不支持或其他原因,则抛出异常。
在某些情况下,更改指定的字段会导致结果的日期时间无效,如更改从1月31日至二月的月将使月无效的日期无效。在这样的情况下,该字段是负责解决日期。通常情况下,它会选择以前的有效日期,这将是二月的最后一个有效的一天,在这个例子中。
如果该字段是ChronoField然后调整在这里实现。
的INSTANT_SECONDS场将返回与指定的即时日期时间。第二的偏移量和纳米级不变。如果新的即时值超出有效范围,则会抛出DateTimeException。
的OFFSET_SECONDS场将返回与指定的偏移时间。本地日期时间是不变的。如果新的偏移值超出有效范围,则会抛出DateTimeException。
另supported fields将表现为每个匹配的方法LocalDateTime。在这种情况下,偏移量是不计算的一部分,将是不变的。
所有其他ChronoField实例将抛出一个UnsupportedTemporalTypeException。
如果该字段是不是ChronoField,然后通过调用作为参数传递this TemporalField.adjustInto(Temporal, long)得到此方法的结果。在这种情况下,字段决定是否以及如何调整即时。
此实例是不可变的,不受此方法调用的影响。
with 接口
Temporal
field -现场设置的结果,不为空
newValue -场的结果中的新价值
OffsetDateTime
this,不空
DateTimeException -如果该字段不能设置
UnsupportedTemporalTypeException如果字段不支持
ArithmeticException如果数值溢出时
public OffsetDateTime withYear(int year)
OffsetDateTime与年变化。偏移量不影响计算,结果在结果中是相同的。如果一个月的一天是无效的,它将被更改为月的最后一个有效的一天。
此实例是不可变的,不受此方法调用的影响。
year年设置的结果,从min_year到max_year
OffsetDateTime,不空
DateTimeException如果年值无效
public OffsetDateTime withMonth(int month)
OffsetDateTime与月的年变化。偏移量不影响计算,结果在结果中是相同的。如果一个月的一天是无效的,它将被更改为月的最后一个有效的一天。
此实例是不可变的,不受此方法调用的影响。
month -年月在结果集,从1(一月)到12(十二月)
OffsetDateTime,不空
DateTimeException如果年值月是无效的
public OffsetDateTime withDayOfMonth(int dayOfMonth)
OffsetDateTime与月改变的一天。如果得到的
OffsetDateTime无效,则抛出一个异常。偏移量不影响计算,结果在结果中是相同的。
此实例是不可变的,不受此方法调用的影响。
dayOfMonth在结果集内,从1至28
OffsetDateTime,不空
DateTimeException如果月值一天是无效的,或者如果月日年月日是无效的
public OffsetDateTime withDayOfYear(int dayOfYear)
OffsetDateTime与天的年变化。如果得到的
OffsetDateTime无效,则抛出一个异常。
此实例是不可变的,不受此方法调用的影响。
dayOfYear -一年建立在结果的那一天,从1到杂志
OffsetDateTime为主,不为空
DateTimeException如果年值一天是无效的,或者如果一天今年是无效的
public OffsetDateTime withHour(int hour)
OffsetDateTime与一个值改变。
偏移量不影响计算,结果在结果中是相同的。
此实例是不可变的,不受此方法调用的影响。
hour -天在结果集时,从0到23
OffsetDateTime,不空
DateTimeException -如果时间值无效
public OffsetDateTime withMinute(int minute)
OffsetDateTime与分钟小时值改变。
偏移量不影响计算,结果在结果中是相同的。
此实例是不可变的,不受此方法调用的影响。
minute -小时设置在结果的那一刻,从0到59
OffsetDateTime,不空
DateTimeException如果分钟值无效
public OffsetDateTime withSecond(int second)
OffsetDateTime第二分钟值改变。
偏移量不影响计算,结果在结果中是相同的。
此实例是不可变的,不受此方法调用的影响。
second -二分钟设置的结果,从0到59
OffsetDateTime,不空
DateTimeException如果二值无效
public OffsetDateTime withNano(int nanoOfSecond)
OffsetDateTime与纳米二值改变。
偏移量不影响计算,结果在结果中是相同的。
此实例是不可变的,不受此方法调用的影响。
nanoOfSecond -二设置结果纳米,从0到999999999
OffsetDateTime毫微秒,不空
DateTimeException如果Nano值无效
public OffsetDateTime truncatedTo(TemporalUnit unit)
OffsetDateTime与定时。
截断返回原始日期时间的副本,该字段小于指定的单位设置为零的字段。例如,截断与minutes单元组分,第二场零纳米二。
单位必须有一个duration分成标准节长度无余。这包括所有提供的时间单位ChronoUnit和DAYS。其他单位抛出一个异常。
偏移量不影响计算,结果在结果中是相同的。
此实例是不可变的,不受此方法调用的影响。
unit -单位截形,不为空
OffsetDateTime截断,不空
DateTimeException如果无法截断
UnsupportedTemporalTypeException如果单位不支持
public OffsetDateTime plus(TemporalAmount amountToAdd)
这将返回一个OffsetDateTime,在此基础上,用指定的添加量。量通常是Period或Duration但可能是任何其他类型的TemporalAmount接口实现。
计算委托量对象通过调用TemporalAmount.addTo(Temporal)数量,实现免费在任何情况下它的愿望实现,但是它通常称为回plus(long, TemporalUnit)。咨询金额实现的文档,以确定是否可以成功添加。
此实例是不可变的,不受此方法调用的影响。
plus 接口
Temporal
amountToAdd -添加量,不为空
OffsetDateTime,不空
DateTimeException如果还不能
ArithmeticException如果数值溢出时
public OffsetDateTime plus(long amountToAdd, TemporalUnit unit)
这将返回一个OffsetDateTime,基于此,在单元的添加量。如果它是不可能添加的量,因为该单元不支持或其他原因,则抛出异常。
如果该字段是ChronoUnit然后通过LocalDateTime.plus(long, TemporalUnit)之外。偏移量不是计算的一部分,在结果中会保持不变。
如果该字段是不是ChronoUnit,然后通过调用作为参数传递this TemporalUnit.addTo(Temporal, long)得到此方法的结果。在这种情况下,该单元确定是否和如何执行加法。
此实例是不可变的,不受此方法调用的影响。
plus 接口
Temporal
amountToAdd -单位的数量增加的结果,可能是负面的
unit -量的单位添加,不为空
OffsetDateTime,不空
DateTimeException如果还不能
UnsupportedTemporalTypeException如果单位不支持
ArithmeticException如果数值溢出时
public OffsetDateTime plusYears(long years)
OffsetDateTime年指定期间补充。
此方法将指定的金额添加到三个步骤中的年字段中:
例如,2008-02-29(闰年)加一年会导致无效的日期2009-02-29(标准年)。而不是返回一个无效的结果,最后一日的一个月,2009-02-28所代替。
此实例是不可变的,不受此方法调用的影响。
years -加年,可能是负面的
OffsetDateTime,不空
DateTimeException -如果结果超过支持的日期范围
public OffsetDateTime plusMonths(long months)
OffsetDateTime在月期添加指定的。
此方法在三个步骤中添加指定的金额到月字段中:
例如,2007-03-31加一个月会导致无效的日期2007-04-31。而不是返回一个无效的结果,最后一日的一个月,2007-04-30所代替。
此实例是不可变的,不受此方法调用的影响。
months -加个月,可能是负面的
OffsetDateTime补充道,不空
DateTimeException -如果结果超过支持的日期范围
public OffsetDateTime plusWeeks(long weeks)
此方法将指定数量的天场周递增的月和年等要保证结果仍然有效。如果超出最大/最小年,则结果是无效的。
例如,2008-12-31加一周会导致2009-01-07。
此实例是不可变的,不受此方法调用的影响。
weeks -加周,可能是负面的
OffsetDateTime补充道,不空
DateTimeException -如果结果超过支持的日期范围
public OffsetDateTime plusDays(long days)
该方法将指定数量的天场递增的年和月的领域要保证结果仍然有效。如果超出最大/最小年,则结果是无效的。
例如,2008-12-31加一天会导致一。
此实例是不可变的,不受此方法调用的影响。
days -添加的日子,可能是负面的
OffsetDateTime,不空
DateTimeException -如果结果超过支持的日期范围
public OffsetDateTime plusHours(long hours)
OffsetDateTime在指定时间内添加时间。
此实例是不可变的,不受此方法调用的影响。
hours -添加时间,可能是负面的
OffsetDateTime,不空
DateTimeException -如果结果超过支持的日期范围
public OffsetDateTime plusMinutes(long minutes)
OffsetDateTime在几分钟之内指定期间补充。
此实例是不可变的,不受此方法调用的影响。
minutes -添加记录,可能是负面的
OffsetDateTime补充道,不空
DateTimeException -如果结果超过支持的日期范围
public OffsetDateTime plusSeconds(long seconds)
OffsetDateTime在指定时间内增加秒。
此实例是不可变的,不受此方法调用的影响。
seconds -加秒,可能是负面的
OffsetDateTime补充道,不空
DateTimeException -如果结果超过支持的日期范围
public OffsetDateTime plusNanos(long nanos)
OffsetDateTime在纳秒指定期间补充。
此实例是不可变的,不受此方法调用的影响。
nanos -添加纳米,可能是负面的
OffsetDateTime补充道,不空
DateTimeException如果单位不能被添加到该类型
public OffsetDateTime minus(TemporalAmount amountToSubtract)
这将返回一个OffsetDateTime,在此基础上,用指定的金额减去。量通常是Period或Duration但可能是任何其他类型的TemporalAmount接口实现。
计算委托量对象通过调用TemporalAmount.subtractFrom(Temporal)数量,实现自由以任何方式希望实现减法,但它通常需要回minus(long, TemporalUnit)。咨询文档的量的实现,以确定它是否可以成功地减去。
此实例是不可变的,不受此方法调用的影响。
minus 接口
Temporal
amountToSubtract -减去的量,不为空
OffsetDateTime,不空
DateTimeException如果减法不能做
ArithmeticException如果数值溢出时
public OffsetDateTime minus(long amountToSubtract, TemporalUnit unit)
这将返回一个OffsetDateTime,在此基础上,对单位金额减去。如果它是不可能的减去的量,因为该单位不支持或一些其他原因,一个异常被抛出。
这种方法是相当的金额plus(long, TemporalUnit)否定。见该方法充分说明了如何加法,从而减法,作品。
此实例是不可变的,不受此方法调用的影响。
minus 接口
Temporal
amountToSubtract -减去从结果数额的单位,可能是负面的
unit -金额单位减,不为空
OffsetDateTime,不空
DateTimeException如果减法不能做
UnsupportedTemporalTypeException如果单位不支持
ArithmeticException如果数值溢出时
public OffsetDateTime minusYears(long years)
OffsetDateTime与指定期在年中减去。
该方法中减去指定的金额从三步来场:
例如,2008-02-29(闰年)减去一年会导致无效的日期2009-02-29(标准年)。而不是返回一个无效的结果,最后一日的一个月,2009-02-28所代替。
此实例是不可变的,不受此方法调用的影响。
years -减去年,可能是负面的
OffsetDateTime,不空
DateTimeException -如果结果超过支持的日期范围
public OffsetDateTime minusMonths(long months)
OffsetDateTime与指定期个月减去。
该方法中减去指定的金额从三步月场:
例如,2007-03-31减去一个月会导致无效的日期2007-04-31。而不是返回一个无效的结果,最后一日的一个月,2007-04-30所代替。
此实例是不可变的,不受此方法调用的影响。
months -减去个月,可能是负面的
OffsetDateTime,不空
DateTimeException -如果结果超过支持的日期范围
public OffsetDateTime minusWeeks(long weeks)
OffsetDateTime在周中减去指定的时间。
该方法在周中减去指定的金额从天场递减的年份和月份等要保证结果仍然有效。如果超出最大/最小年,则结果是无效的。
例如,2008-12-31减去一周会导致2009-01-07。
此实例是不可变的,不受此方法调用的影响。
weeks -减去的数周,可能是负面的
OffsetDateTime,不空
DateTimeException -如果结果超过支持的日期范围
public OffsetDateTime minusDays(long days)
OffsetDateTime与指定的期间天数减去。
该方法中减去指定的金额从天场递增的年和月的领域要保证结果仍然有效。如果超出最大/最小年,则结果是无效的。
例如,2008-12-31减去一天会导致一。
此实例是不可变的,不受此方法调用的影响。
days -减去几天,可能是负面的
OffsetDateTime,不空
DateTimeException -如果结果超过支持的日期范围
public OffsetDateTime minusHours(long hours)
OffsetDateTime减去指定的时间在小时。
此实例是不可变的,不受此方法调用的影响。
hours -减小时,可能是负面的
OffsetDateTime,不空
DateTimeException -如果结果超过支持的日期范围
public OffsetDateTime minusMinutes(long minutes)
OffsetDateTime在几分钟之内减去指定的时间。
此实例是不可变的,不受此方法调用的影响。
minutes -减分,可能是负面的
OffsetDateTime减去一,不空
DateTimeException -如果结果超过支持的日期范围
public OffsetDateTime minusSeconds(long seconds)
OffsetDateTime与指定期秒减去。
此实例是不可变的,不受此方法调用的影响。
seconds -减去秒,可能是负面的
OffsetDateTime减去一,不空
DateTimeException -如果结果超过支持的日期范围
public OffsetDateTime minusNanos(long nanos)
OffsetDateTime减去指定的时间在纳秒。
此实例是不可变的,不受此方法调用的影响。
nanos -减去这些可能是负面的
OffsetDateTime,不空
DateTimeException -如果结果超过支持的日期范围
public <R> R query(TemporalQuery<R> query)
此查询使用指定的查询策略对象使用此日期时间。的TemporalQuery对象定义了用来获得结果的逻辑。阅读查询的文档,了解该方法的结果将是什么。
这种方法的结果是通过调用指定的查询通过this作为论据的TemporalQuery.queryFrom(TemporalAccessor)方法得到的。
query 接口
TemporalAccessor
R -结果的类型
query -调用查询,不空
DateTimeException如果无法查询(查询所定义)
ArithmeticException如果数值溢出时(由查询定义)
public Temporal adjustInto(Temporal temporal)
这将返回一个相同的可观察类型的时间对象作为偏移量,日期和时间的输入与此相同。
调整是相当于用Temporal.with(TemporalField, long)三次,通过ChronoField.EPOCH_DAY,ChronoField.NANO_OF_DAY和ChronoField.OFFSET_SECONDS的领域。
在大多数情况下,更清晰的用Temporal.with(TemporalAdjuster)反向调用模式:
这两条线是等价的,但第二种方法是建议时间= thisoffsetdatetime adjustinto(时间);时间=(thisoffsetdatetime)与时间;
此实例是不可变的,不受此方法调用的影响。
adjustInto 接口
TemporalAdjuster
temporal -调整目标对象,不为空
DateTimeException如果无法适应
ArithmeticException如果数值溢出时
public long until(Temporal endExclusive, TemporalUnit unit)
这两OffsetDateTime计算对象之间的时间量在一个TemporalUnit条款。开始和结束点this和指定的日期时间。结果将是负的,如果结束之前开始。例如,两个日期时间之间的时间可以计算startDateTime.until(endDateTime, DAYS)。
的Temporal传递给此方法转换为OffsetDateTime使用from(TemporalAccessor)。如果偏移量之间的两个日期时间不同,指定的结束日期时间被归一化,以具有相同的偏移量,作为此日期时间。
计算返回一个整数,表示两个日期之间的完整单元的数目。例如,在2012-06-15t00:00z和2012-08-14t23:59z之间月期只有一个月很短,两个月一分钟。
使用这种方法有两个等效的方法。首先是调用这个方法。二是用TemporalUnit.between(Temporal, Temporal):
这两条线是等价的金额=开始,直到(结束,月);金额=月间(开始,结束);的选择应基于使得代码更易读。
计算中实现该方法ChronoUnit。单位NANOS,MICROS,MILLIS,SECONDS,MINUTES,HOURS和HALF_DAYS,DAYS,WEEKS,MONTHS,YEARS,DECADES,CENTURIES,MILLENNIA和ERAS支持。其他ChronoUnit值将抛出一个异常。
如果单位不ChronoUnit,然后通过调用TemporalUnit.between(Temporal, Temporal) this作为第一个参数传递和转换的输入时间作为第二个参数给出了这个方法的结果。
此实例是不可变的,不受此方法调用的影响。
until 接口
Temporal
endExclusive -结束日期,独家的,它被转换为一个
OffsetDateTime,不空
unit -单位量来衡量,不为空
DateTimeException如果金额无法计算,或结束时间不能转换为
OffsetDateTime
UnsupportedTemporalTypeException如果单位不支持
ArithmeticException如果数值溢出时
public String format(DateTimeFormatter formatter)
这个日期将被传递到格式化程序产生一个字符串。
formatter -格式化程序使用,不为空
DateTimeException如果打印时发生错误
public ZonedDateTime atZoneSameInstant(ZoneId zone)
ZonedDateTime确保结果具有相同的瞬间。
这将返回一个ZonedDateTime从这个日期时间形成和指定的时区。这种转换将忽略可见的本地日期时间,并使用底层的即时。这避免了任何问题,与本地时间线的差距或重叠。结果可能有不同的值字段,如小时,分钟,甚至一天。
试图保留的字段的值,使用atZoneSimilarLocal(ZoneId)。使用偏移的区域ID,使用toZonedDateTime()。
zone -时区使用,不为空
public ZonedDateTime atZoneSimilarLocal(ZoneId zone)
ZonedDateTime一直保持相同的本地日期和时间。
这将返回一个ZonedDateTime从这个日期时间形成和指定的时区。在可能的情况下,结果将有相同的本地日期时间作为此对象。
时区的规则,如日光节约,这意味着不是每一个时间在本地时间线存在。如果本地日期时间在间隙或重叠根据规则解析器是用来确定所得的当地时间和偏移。该方法采用ZonedDateTime.ofLocal(LocalDateTime, ZoneId, ZoneOffset)尽可能保留从该实例的偏移。
对缝隙和重叠的更精细的控制有两种方式。如果你只是想使用后抵消重叠然后调用此方法后立即ZonedDateTime.withLaterOffsetAtOverlap()。
在一瞬间,不论当地时间线创建一个分区的日期时间,使用atZoneSameInstant(ZoneId)。使用偏移的区域ID,使用toZonedDateTime()。
zone -时区使用,不为空
public OffsetTime toOffsetTime()
OffsetTime日期时间。
这将返回一个相同的本地时间和偏移量的偏移时间。
public ZonedDateTime toZonedDateTime()
ZonedDateTime使用偏移为区
这创造了尽可能简单的ZonedDateTime使用偏移的区域ID。
控制使用时间区,看到atZoneSameInstant(ZoneId)和atZoneSimilarLocal(ZoneId)。
public Instant toInstant()
Instant日期时间。
这将返回代表时间轴上的同一点为这一Instant日期时间。
Instant,不空
public long toEpochSecond()
这使得这个日期时间转换为价值的epoch-seconds场。这主要是用于低级别的转换,而不是一般的应用程序使用。
public int compareTo(OffsetDateTime other)
OffsetDateTime到另一个日期时间。
比较是基于即时然后在本地日期时间。这是“等于”一致,所定义的Comparable。
例如,下面是比较器的顺序:
2008-12-03T10:30+01:002008-12-03T11:00+01:002008-12-03T12:00+02:002008-12-03T11:30+01:002008-12-03T12:00+01:002008-12-03T12:30+01:00equals()。
compareTo 接口
Comparable<OffsetDateTime>
other的其他时间相比,不空
public boolean isAfter(OffsetDateTime other)
这种方法不同于在它只对日期时间的即时compareTo(java.time.OffsetDateTime)和equals(java.lang.Object)比较。这相当于使用dateTime1.toInstant().isAfter(dateTime2.toInstant());。
other的其他时间相比,不空
public boolean isBefore(OffsetDateTime other)
这种方法不同于在compareTo(java.time.OffsetDateTime)在比较,只是比较的日期时间的瞬间。这相当于使用dateTime1.toInstant().isBefore(dateTime2.toInstant());。
other的其他时间相比,不空
public boolean isEqual(OffsetDateTime other)
这种方法不同于在它只对日期时间的即时compareTo(java.time.OffsetDateTime)和equals(java.lang.Object)比较。这相当于使用dateTime1.toInstant().equals(dateTime2.toInstant());。
other的其他时间相比,不空
public boolean equals(Object obj)
比较是基于本地日期时间和偏移量的。在时间线的一瞬间相比,使用isEqual(java.time.OffsetDateTime)。OffsetDateTime型只有对象相比,其他类型返回false。
equals 方法重写,继承类
Object
obj -检查对象,空返回false
Object.hashCode(),
HashMap
public int hashCode()
hashCode 方法重写,继承类
Object
Object.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)
public String toString()
String,如
2007-12-03T10:15:30+01:00。
输出将下列ISO-8601格式:
uuuu-MM-dd'T'HH:mmXXXXXuuuu-MM-dd'T'HH:mm:ssXXXXXuuuu-MM-dd'T'HH:mm:ss.SSSXXXXXuuuu-MM-dd'T'HH:mm:ss.SSSSSSXXXXXuuuu-MM-dd'T'HH:mm:ss.SSSSSSSSSXXXXX Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.