本文整理了Java中java.time.OffsetDateTime.toZonedDateTime()
方法的一些代码示例,展示了OffsetDateTime.toZonedDateTime()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.toZonedDateTime()
方法的具体详情如下:
包路径:java.time.OffsetDateTime
类名称:OffsetDateTime
方法名:toZonedDateTime
[英]Converts this date-time to a ZonedDateTime using the offset as the zone ID.
This creates the simplest possible ZonedDateTime using the offset as the zone ID.
To control the time-zone used, see #atZoneSameInstant(ZoneId) and #atZoneSimilarLocal(ZoneId).
[中]使用偏移量作为分区ID,将此日期时间转换为ZonedDateTime。
这将使用偏移量作为分区ID创建最简单的分区DateTime。
要控制所使用的时区,请参见#atzonesamainstant(ZoneId)和#atzonesmilarLocal(ZoneId)。
代码示例来源:origin: spring-projects/spring-framework
@Override
public ZonedDateTime convert(OffsetDateTime source) {
return source.toZonedDateTime();
}
}
代码示例来源:origin: org.springframework/spring-context
@Override
public ZonedDateTime convert(OffsetDateTime source) {
return source.toZonedDateTime();
}
}
代码示例来源:origin: neo4j/neo4j
public static DateTimeValue datetime( OffsetDateTime datetime )
{
return new DateTimeValue( requireNonNull( datetime, "OffsetDateTime" ).toZonedDateTime() );
}
代码示例来源:origin: spring-cloud/spring-cloud-gateway
@Override
public ZonedDateTime convert(String source) {
ZonedDateTime dateTime;
try {
long epoch = Long.parseLong(source);
dateTime = Instant.ofEpochMilli(epoch).atOffset(ZoneOffset.ofTotalSeconds(0))
.toZonedDateTime();
} catch (NumberFormatException e) {
// try ZonedDateTime instead
dateTime = ZonedDateTime.parse(source);
}
return dateTime;
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
@SuppressWarnings("unchecked")
public <X> X unwrap(OffsetTime offsetTime, Class<X> type, WrapperOptions options) {
if ( offsetTime == null ) {
return null;
}
if ( OffsetTime.class.isAssignableFrom( type ) ) {
return (X) offsetTime;
}
if ( java.sql.Time.class.isAssignableFrom( type ) ) {
return (X) java.sql.Time.valueOf( offsetTime.toLocalTime() );
}
final ZonedDateTime zonedDateTime = offsetTime.atDate( LocalDate.of( 1970, 1, 1 ) ).toZonedDateTime();
if ( Timestamp.class.isAssignableFrom( type ) ) {
return (X) Timestamp.valueOf( zonedDateTime.toLocalDateTime() );
}
if ( Calendar.class.isAssignableFrom( type ) ) {
return (X) GregorianCalendar.from( zonedDateTime );
}
final Instant instant = zonedDateTime.toInstant();
if ( Long.class.isAssignableFrom( type ) ) {
return (X) Long.valueOf( instant.toEpochMilli() );
}
if ( java.util.Date.class.isAssignableFrom( type ) ) {
return (X) java.util.Date.from( instant );
}
throw unknownUnwrap( type );
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
@SuppressWarnings("unchecked")
public <X> X unwrap(OffsetDateTime offsetDateTime, Class<X> type, WrapperOptions options) {
if ( offsetDateTime == null ) {
return null;
}
if ( OffsetDateTime.class.isAssignableFrom( type ) ) {
return (X) offsetDateTime;
}
if ( Calendar.class.isAssignableFrom( type ) ) {
return (X) GregorianCalendar.from( offsetDateTime.toZonedDateTime() );
}
if ( Timestamp.class.isAssignableFrom( type ) ) {
return (X) Timestamp.from( offsetDateTime.toInstant() );
}
if ( java.sql.Date.class.isAssignableFrom( type ) ) {
return (X) java.sql.Date.from( offsetDateTime.toInstant() );
}
if ( java.sql.Time.class.isAssignableFrom( type ) ) {
return (X) java.sql.Time.from( offsetDateTime.toInstant() );
}
if ( Date.class.isAssignableFrom( type ) ) {
return (X) Date.from( offsetDateTime.toInstant() );
}
if ( Long.class.isAssignableFrom( type ) ) {
return (X) Long.valueOf( offsetDateTime.toInstant().toEpochMilli() );
}
throw unknownUnwrap( type );
}
代码示例来源:origin: apache/servicemix-bundles
@Override
public ZonedDateTime convert(OffsetDateTime source) {
return source.toZonedDateTime();
}
}
代码示例来源:origin: stackoverflow.com
static final DateTimeFormatter DATE_TIME_OPTIONAL_OFFSET =
DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss[xxx]");
OffsetDateTime odt =
DATE_TIME_OPTIONAL_OFFSET.withZone(ZoneOffset.UTC).parse(input, OffsetDateTime::from);
ZonedDateTime zdt = odt.toZonedDateTime(); // containing a fixed offset
代码示例来源:origin: org.codehaus.groovy/groovy-datetime
/**
* Returns a generally equivalent instance of {@link java.util.Calendar}.
* The time value of the returned calendar is truncated to milliseconds and the time zone
* is based on the offset of this date/time.
*
* @param self an OffsetDateTime
* @return a java.util.Calendar
* @since 2.5.0
*/
public static Calendar toCalendar(final OffsetDateTime self) {
return toCalendar(self.toZonedDateTime());
}
代码示例来源:origin: org.neo4j.driver/neo4j-java-driver
public static Value value( OffsetDateTime offsetDateTime )
{
return new DateTimeValue( offsetDateTime.toZonedDateTime() );
}
代码示例来源:origin: salesforce/grpc-java-contrib
public static ZonedDateTime toZonedDateTimeUtc(@Nonnull Timestamp timestamp) {
checkNotNull(timestamp, "timestamp");
return toOffsetDateTimeUtc(timestamp).toZonedDateTime();
}
代码示例来源:origin: com.salesforce.servicelibs/grpc-contrib
public static ZonedDateTime toZonedDateTimeUtc(@Nonnull Timestamp timestamp) {
checkNotNull(timestamp, "timestamp");
return toOffsetDateTimeUtc(timestamp).toZonedDateTime();
}
代码示例来源:origin: org.neo4j/neo4j-values
public static DateTimeValue datetime( OffsetDateTime datetime )
{
return new DateTimeValue( requireNonNull( datetime, "OffsetDateTime" ).toZonedDateTime() );
}
代码示例来源:origin: brettwooldridge/HikariJSON
private Date parseDate(String stringHolder)
{
return dateCache.computeIfAbsent(stringHolder, (k) -> {
final OffsetDateTime dateTime = OffsetDateTime.parse(stringHolder);
return GregorianCalendar.from(dateTime.toZonedDateTime()).getTime();
});
}
代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core
@Override
public ZonedDateTime time(ZonedDateTime from) {
if (from == null) {
return null;
}
OffsetTime offsetTime = from.toOffsetDateTime().toOffsetTime();
return offsetTime.atDate(LocalDate.MIN).toZonedDateTime();
}
代码示例来源:origin: org.apache.james/james-server-data-jpa
@Override
public ZonedDateTime getActivationDateForActiveScript(User user) throws StorageException, ScriptNotFoundException {
Optional<JPASieveScript> script = findActiveSieveScript(user);
JPASieveScript activeSieveScript = script.orElseThrow(() -> new ScriptNotFoundException("Unable to find active script for user " + user.asString()));
return activeSieveScript.getActivationDateTime().toZonedDateTime();
}
代码示例来源:origin: goldmansachs/jdmn
@Override
public ZonedDateTime time(ZonedDateTime from) {
if (from == null) {
return null;
}
OffsetTime offsetTime = from.toOffsetDateTime().toOffsetTime();
return offsetTime.atDate(LocalDate.MIN).toZonedDateTime();
}
代码示例来源:origin: com.impossibl.pgjdbc-ng/pgjdbc-ng
@Override
protected Object decodeValue(Context context, Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Class<?> targetClass, Object targetContext) throws IOException {
Calendar calendar = targetContext != null ? (Calendar) targetContext : Calendar.getInstance();
if (buffer.equals(POS_INFINITY) || buffer.equals(NEG_INFINITY)) {
return convertInfinityOutput(buffer.equals(POS_INFINITY), type, targetClass);
}
TemporalAccessor parsed = context.getTimestampFormat().getParser().parse(buffer);
ZonedDateTime dateTime;
if (parsed.isSupported(ChronoField.OFFSET_SECONDS)) {
dateTime = OffsetDateTime.from(parsed).toZonedDateTime().withZoneSameInstant(UTC_ID);
}
else {
dateTime = LocalDateTime.from(parsed).atZone(calendar.getTimeZone().toZoneId());
}
return convertOutput(context, type, dateTime, targetClass, calendar);
}
代码示例来源:origin: jneat/mybatis-types
@Override
public void setNonNullParameter(PreparedStatement ps, int i, OffsetDateTime parameter, JdbcType jdbcType) throws SQLException {
// Postgres do not work with offsets > than 15 hours, maybe other DBs too
int offset = parameter.get(ChronoField.OFFSET_SECONDS);
if (Math.abs(offset) > 54000) {
parameter = parameter.withOffsetSameInstant(ZoneOffset.ofHours(offset > 0 ? 15 : -15));
}
ps.setTimestamp(
i,
Timestamp.from(parameter.toInstant()),
GregorianCalendar.from(parameter.toZonedDateTime())
);
}
代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core
private ZonedDateTime makeDateTime(String literal) {
if (StringUtils.isBlank(literal)) {
return null;
}
try {
literal = DateTimeUtil.fixDateTimeFormat(literal);
if (DateTimeUtil.hasZone(literal)) {
return makeZonedDateTime(literal);
} else if (DateTimeUtil.hasOffset(literal)) {
return OffsetDateTime.parse(literal).toZonedDateTime();
} else {
return makeZonedDateTime(literal + "Z");
}
} catch (Throwable e) {
String message = String.format("makeDateTime(%s)", literal);
logError(message, e);
return null;
}
}
内容来源于网络,如有侵权,请联系作者删除!