java.time.ZonedDateTime.from()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(220)

本文整理了Java中java.time.ZonedDateTime.from()方法的一些代码示例,展示了ZonedDateTime.from()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonedDateTime.from()方法的具体详情如下:
包路径:java.time.ZonedDateTime
类名称:ZonedDateTime
方法名:from

ZonedDateTime.from介绍

[英]Obtains an instance of ZonedDateTime 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 ZonedDateTime.

The conversion will first obtain a ZoneId. It will then try to obtain an instant. If that fails it will try to obtain a local date-time. The zoned date time will either be a combination of ZoneId and instant, or ZoneId and local date-time.

This method matches the signature of the functional interface TemporalQueryallowing it to be used in queries via method reference, ZonedDateTime::from.
[中]从时间对象获取ZoneDateTime的实例。
临时助理代表某种形式的日期和时间信息。此工厂将任意时间对象转换为ZoneDateTime的实例。
转换将首先获得ZoneId。然后,它将尝试获得一个瞬间。如果失败,它将尝试获取本地日期和时间。分区日期时间可以是ZoneId和instant的组合,也可以是ZoneId和本地日期时间的组合。
此方法匹配函数接口TemporalQueryLow的签名,通过方法引用ZonedDateTime::from将其用于查询。

代码示例

代码示例来源:origin: prontera/spring-cloud-rest-tcc

@Override
  public ZonedDateTime convertFrom(ZonedDateTime odt, Type<ZonedDateTime> type, MappingContext mappingContext) {
    return ZonedDateTime.from(odt);
  }
}

代码示例来源:origin: prontera/spring-cloud-rest-tcc

@Override
public ZonedDateTime convertTo(ZonedDateTime odt, Type<ZonedDateTime> type, MappingContext mappingContext) {
  return ZonedDateTime.from(odt);
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public ZonedDateTime fromString(String string) {
  return ZonedDateTime.from( ZonedDateTimeType.FORMATTER.parse( string ) );
}

代码示例来源:origin: apache/nifi

private String prettyResult(Object entryValue, String tzID) {
  if (entryValue instanceof InetAddress ) {
    return ((InetAddress) entryValue).getHostAddress();
  } else if (entryValue instanceof Date) {
    ZonedDateTime zdt = ZonedDateTime.from(((Date) entryValue).toInstant().atZone(ZoneId.of(tzID)));
    return(String.valueOf(zdt.format(dateTimeFormatter)));
  } else {
    return String.valueOf(entryValue);
  }
}

代码示例来源:origin: chewiebug/GCViewer

@Override
protected Object clone() throws CloneNotSupportedException {
  AbstractGCEvent<T> clonedEvent = (AbstractGCEvent<T>)super.clone();
  if (getDatestamp() != null) {
    clonedEvent.setDateStamp(ZonedDateTime.from(this.getDatestamp()));
  }
  if (getExtendedType() != null) {
    clonedEvent.setExtendedType(new ExtendedType(getExtendedType().getType(), getExtendedType().fullName));
  }
  if (details != null) {
    List<T> detailClones = new ArrayList<>();
    for (T t : details) {
      detailClones.add((T)t.clone());
    }
    clonedEvent.details = detailClones;
  }
  // don't need to do anything with "generation", because that value is reset by the "add()" method
  return clonedEvent;
}

代码示例来源:origin: wildfly/wildfly

break;
case HALF_DAY:
  ZonedDateTime halfDay = ZonedDateTime.from(zonedDateTime).truncatedTo(ChronoUnit.DAYS)
      .plus(1, ChronoUnit.HALF_DAYS);
  if ( zonedDateTime.isBefore(halfDay) ) {

代码示例来源:origin: eclipse/smarthome

public DateTimeType(ZonedDateTime zoned) {
  this.zonedDateTime = ZonedDateTime.from(zoned).withFixedOffsetZone();
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Parse the given input into a Joda {@link DateTime}.
 */
default DateTime parseJoda(String input) {
  ZonedDateTime dateTime = ZonedDateTime.from(parse(input));
  return new DateTime(dateTime.toInstant().toEpochMilli(), DateUtils.zoneIdToDateTimeZone(dateTime.getZone()));
}

代码示例来源:origin: com.github.seratch/java-time-backport

@Override
  public ZonedDateTime queryFrom(TemporalAccessor temporal) {
    return ZonedDateTime.from(temporal);
  }
};

代码示例来源:origin: org.apereo.cas/cas-server-support-x509-core

/**
 * @return Returns the expirationDate.
 */
public ZonedDateTime getExpirationDate() {
  return this.expirationDate == null ? null : ZonedDateTime.from(this.expirationDate);
}

代码示例来源:origin: org.apereo.cas/cas-server-core-util-api

/**
 * Utility for creating a ZonedDateTime object from a ZonedDateTime.
 *
 * @param time ZonedDateTime to be copied
 * @return ZonedDateTime representing time
 */
public static ZonedDateTime zonedDateTimeOf(final TemporalAccessor time) {
  return ZonedDateTime.from(time);
}

代码示例来源:origin: org.apache.wicket/wicket-util

@Override
protected ZonedDateTime createTemporal(TemporalAccessor temporalAccessor)
{
  return ZonedDateTime.from(temporalAccessor);
}

代码示例来源:origin: net.arnx/jsonic

@Override
  public ZonedDateTime queryFrom(TemporalAccessor temporal) {
    return ZonedDateTime.from(temporal);
  }
},

代码示例来源:origin: com.github.ebaydatameta/dom-core

/**
 * Parses the argument using {@link DateTimeFormatter#ISO_DATE_TIME}.
 */
public ZonedDateTime parse(final String text) {
 return ZonedDateTime.from(ISO_DATE_TIME.parse(text));
}

代码示例来源:origin: org.tiogasolutions.dev/tioga-dev-common

public ZonedDateTime toZonedDateTime(long date) {
 if (date == 0) {
  return null;
 } else if (date > 0) {
  Instant instant = Instant.ofEpochMilli(date);
  return ZonedDateTime.from(instant.atZone(zoneId));
 } else {
  throw new IllegalArgumentException("The value \"date\" must be greater than or equal to zero.");
 }
}

代码示例来源:origin: org.apache.nifi/nifi-standard-processors

private String prettyResult(Object entryValue, String tzID) {
  if (entryValue instanceof InetAddress ) {
    return ((InetAddress) entryValue).getHostAddress();
  } else if (entryValue instanceof Date) {
    ZonedDateTime zdt = ZonedDateTime.from(((Date) entryValue).toInstant().atZone(ZoneId.of(tzID)));
    return(String.valueOf(zdt.format(dateTimeFormatter)));
  } else {
    return String.valueOf(entryValue);
  }
}

代码示例来源:origin: org.cactoos/cactoos

/**
 * Parses the date using the formatter to create
 *  {@link ZonedDateTime} instances.
 * @param date The date to parse.
 * @param formatter The formatter to use.
 */
public ZonedDateTimeOf(final CharSequence date,
  final DateTimeFormatter formatter) {
  this.parsed = new UncheckedScalar<>(
    () -> ZonedDateTime.from(formatter.parse(date))
  );
}

代码示例来源:origin: yegor256/cactoos

/**
 * Parses the date using the formatter to create
 *  {@link ZonedDateTime} instances.
 * @param date The date to parse.
 * @param formatter The formatter to use.
 */
public ZonedDateTimeOf(final CharSequence date,
  final DateTimeFormatter formatter) {
  this.parsed = new UncheckedScalar<>(
    () -> ZonedDateTime.from(formatter.parse(date))
  );
}

代码示例来源:origin: yegor256/cactoos

/**
 * Parses the date using the formatter to create
 *  {@link OffsetDateTime} instances.
 * @param date The date to parse.
 * @param formatter The formatter to use.
 */
public OffsetDateTimeOf(final CharSequence date,
  final DateTimeFormatter formatter) {
  this.parsed = new UncheckedScalar<>(
    () -> ZonedDateTime.from(formatter.parse(date)).toOffsetDateTime()
  );
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public static ZonedDateTime toZonedDateTime(TemporalAccessor accessor, ZonedDateTime defaults) {
  try {
    return ZonedDateTime.from(accessor);
  } catch (DateTimeException e ) {

相关文章

ZonedDateTime类方法