當前位置: 首頁>>代碼示例>>Java>>正文


Java ZoneId.from方法代碼示例

本文整理匯總了Java中java.time.ZoneId.from方法的典型用法代碼示例。如果您正苦於以下問題:Java ZoneId.from方法的具體用法?Java ZoneId.from怎麽用?Java ZoneId.from使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.ZoneId的用法示例。


在下文中一共展示了ZoneId.from方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: zonedDateTime

import java.time.ZoneId; //導入方法依賴的package包/類
/**
 * Creates a zoned date-time in this chronology from another date-time object.
 * <p>
 * This creates a date-time in this chronology based on the specified {@code DateTimeAccessor}.
 * <p>
 * This should obtain a {@code ZoneId} using {@link ZoneId#from(DateTimeAccessor)}. The date-time should be
 * obtained by obtaining an {@code Instant}. If that fails, the local date-time should be used.
 * 
 * @param dateTime the date-time object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 */
public ChronoZonedDateTime<C> zonedDateTime(DateTimeAccessor dateTime) {

  try {
    ZoneId zoneId = ZoneId.from(dateTime);
    ChronoDateTimeImpl<C> cldt;
    try {
      Instant instant = Instant.from(dateTime);
      cldt = localInstant(instant, zoneId);
    } catch (DateTimeException ex1) {
      cldt = ensureChronoLocalDateTime(localDateTime(dateTime));
    }
    return ChronoZonedDateTimeImpl.ofBest(cldt, zoneId, null);
  } catch (DateTimeException ex) {
    throw new DateTimeException("Unable to convert DateTimeAccessor to ZonedDateTime: " + dateTime.getClass(), ex);
  }
}
 
開發者ID:kiegroup,項目名稱:optashift-employee-rostering,代碼行數:29,代碼來源:Chrono.java

示例2: zonedDateTime

import java.time.ZoneId; //導入方法依賴的package包/類
/**
 * Obtains a {@code ChronoZonedDateTime} in this chronology from another temporal object.
 * <p>
 * This obtains a zoned date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion will first obtain a {@code ZoneId} from the temporal object,
 * falling back to a {@code ZoneOffset} if necessary. It will then try to obtain
 * an {@code Instant}, falling back to a {@code ChronoLocalDateTime} if necessary.
 * The result will be either the combination of {@code ZoneId} or {@code ZoneOffset}
 * with {@code Instant} or {@code ChronoLocalDateTime}.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::zonedDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoZonedDateTime#from(TemporalAccessor)
 */
default ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
    try {
        ZoneId zone = ZoneId.from(temporal);
        try {
            Instant instant = Instant.from(temporal);
            return zonedDateTime(instant, zone);

        } catch (DateTimeException ex1) {
            ChronoLocalDateTimeImpl<?> cldt = ChronoLocalDateTimeImpl.ensureValid(this, localDateTime(temporal));
            return ChronoZonedDateTimeImpl.ofBest(cldt, zone, null);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:40,代碼來源:Chronology.java

示例3: factory_from_TemporalAccessor_invalid_noDerive

import java.time.ZoneId; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeException.class)
public void factory_from_TemporalAccessor_invalid_noDerive() {
    ZoneId.from(LocalTime.of(12, 30));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:TCKZoneId.java

示例4: factory_from_TemporalAccessor_null

import java.time.ZoneId; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void factory_from_TemporalAccessor_null() {
    ZoneId.from(null);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:TCKZoneId.java


注:本文中的java.time.ZoneId.from方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。