本文整理了Java中java.time.ZoneOffset.from()
方法的一些代码示例,展示了ZoneOffset.from()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneOffset.from()
方法的具体详情如下:
包路径:java.time.ZoneOffset
类名称:ZoneOffset
方法名:from
[英]Obtains an instance of ZoneOffset from a temporal object.
A TemporalAccessor represents some form of date and time information. This factory converts the arbitrary temporal object to an instance of ZoneOffset.
The conversion uses the TemporalQueries#offset() query, which relies on extracting the ChronoField#OFFSET_SECONDS field.
This method matches the signature of the functional interface TemporalQueryallowing it to be used in queries via method reference, ZoneOffset::from.
[中]从时间对象获取ZoneOffset的实例。
临时助理代表某种形式的日期和时间信息。该工厂将任意时间对象转换为ZoneOffset的实例。
转换使用TemporalQueries#offset()查询,该查询依赖于提取ChronoField#offset_SECONDS字段。
此方法匹配函数接口TemporalQueryLow的签名,通过方法引用ZoneOffset::from将其用于查询。
代码示例来源:origin: DV8FromTheWorld/JDA
try
offset = ZoneOffset.from(temporal);
代码示例来源:origin: com.github.seratch/java-time-backport
@Override
public ZoneOffset queryFrom(TemporalAccessor temporal) {
return ZoneOffset.from(temporal);
}
};
代码示例来源:origin: OpenWiseSolutions/openhub-framework
@Nullable
public static OffsetDateTime parseDateTime(@Nullable String dtStr) {
if (dtStr == null) {
return null;
}
// An unspecified time zone is exactly that - unspecified. No more, no less. It's not saying it's in UTC,
// nor is it saying it's in the local time zone or any other time zone, it's just saying that the time
// read from some clock somewhere was that time
// see http://stackoverflow.com/questions/20670041/what-is-the-default-time-zone-for-an-xml-schema-datetime-if-not-specified
// => we use default time zone to the current time
TemporalAccessor dt = DateTimeFormatter.ISO_DATE_TIME.parseBest(dtStr, OffsetDateTime::from, LocalDateTime::from);
if (dt instanceof OffsetDateTime) {
return (OffsetDateTime) dt;
} else {
return OffsetDateTime.of((LocalDateTime)dt, ZoneOffset.from(ZonedDateTime.now()));
}
}
代码示例来源:origin: OpenWiseSolutions/openhub-framework
@Nullable
public static OffsetDateTime parseDate(@Nullable String dateStr) {
if (dateStr == null) {
return null;
}
// parsing has two steps:
// 1) parse date with offset "2013-10-05+02:00"
// 2) parse date without offset "2013-10-05"
try {
return OffsetDateTime.from(ISO_OFFSET_DATE_MIDNIGHT.parse(dateStr));
} catch (DateTimeParseException ex) {
TemporalAccessor dt = DateTimeFormatter.ISO_DATE.parseBest(dateStr, OffsetDateTime::from, LocalDate::from);
if (dt instanceof OffsetDateTime) {
return (OffsetDateTime) dt;
} else {
LocalDateTime ldt = LocalDateTime.of((LocalDate)dt, LocalTime.now());
return OffsetDateTime.of(ldt.truncatedTo(ChronoUnit.DAYS), ZoneOffset.from(ZonedDateTime.now()));
}
}
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Obtains an instance of {@code OffsetTime} from a temporal object.
* <p>
* A {@code TemporalAccessor} represents some form of date and time information.
* This factory converts the arbitrary temporal object to an instance of {@code OffsetTime}.
* <p>
* The conversion extracts and combines {@code LocalTime} and {@code ZoneOffset}.
* <p>
* This method matches the signature of the functional interface {@link TemporalQuery}
* allowing it to be used in queries via method reference, {@code OffsetTime::from}.
*
* @param temporal the temporal object to convert, not null
* @return the offset time, not null
* @throws DateTimeException if unable to convert to an {@code OffsetTime}
*/
public static OffsetTime from(TemporalAccessor temporal) {
if (temporal instanceof OffsetTime) {
return (OffsetTime) temporal;
}
try {
LocalTime time = LocalTime.from(temporal);
ZoneOffset offset = ZoneOffset.from(temporal);
return new OffsetTime(time, offset);
} catch (DateTimeException ex) {
throw new DateTimeException("Unable to obtain OffsetTime from TemporalAccessor: " +
temporal + ", type " + temporal.getClass().getName());
}
}
代码示例来源:origin: mewna/catnip
offset = ZoneOffset.from(temporal);
} catch(final DateTimeException ignored) {
offset = ZoneOffset.UTC;
代码示例来源:origin: hibernate/hibernate-search
ZoneOffset offset = ZoneOffset.from( temporal );
LocalDateTime ldt = LocalDateTime.from( temporal );
return ZonedDateTime.ofInstant( ldt, offset, zone );
代码示例来源:origin: org.infinispan/infinispan-embedded-query
ZoneOffset offset = ZoneOffset.from( temporal );
LocalDateTime ldt = LocalDateTime.from( temporal );
return ZonedDateTime.ofInstant( ldt, offset, zone );
代码示例来源:origin: com.github.seratch/java-time-backport
ZoneOffset offset = ZoneOffset.from(temporal);
try {
LocalDateTime ldt = LocalDateTime.from(temporal);
内容来源于网络,如有侵权,请联系作者删除!