当前位置: 首页>>代码示例>>Java>>正文


Java TemporalAccessor.getClass方法代码示例

本文整理汇总了Java中java.time.temporal.TemporalAccessor.getClass方法的典型用法代码示例。如果您正苦于以下问题:Java TemporalAccessor.getClass方法的具体用法?Java TemporalAccessor.getClass怎么用?Java TemporalAccessor.getClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.temporal.TemporalAccessor的用法示例。


在下文中一共展示了TemporalAccessor.getClass方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: zonedDateTime

import java.time.temporal.TemporalAccessor; //导入方法依赖的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

示例2: from

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code ChronoZonedDateTime} from a temporal object.
 * <p>
 * This creates a zoned date-time 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 extracts and combines the chronology, date, time and zone
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#zonedDateTime(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoZonedDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date-time, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoZonedDateTime}
 * @see Chronology#zonedDateTime(TemporalAccessor)
 */
static ChronoZonedDateTime<?> from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoZonedDateTime) {
        return (ChronoZonedDateTime<?>) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.zonedDateTime(temporal);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:ChronoZonedDateTime.java

示例3: from

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code ChronoLocalDate} from a temporal object.
 * <p>
 * This obtains a local date 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 ChronoLocalDate}.
 * <p>
 * The conversion extracts and combines the chronology and the date
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#date(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoLocalDate::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoLocalDate}
 * @see Chronology#date(TemporalAccessor)
 */
static ChronoLocalDate from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoLocalDate) {
        return (ChronoLocalDate) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoLocalDate from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.date(temporal);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:ChronoLocalDate.java

示例4: from

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code ChronoLocalDateTime} from a temporal object.
 * <p>
 * This obtains a local date-time 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 ChronoLocalDateTime}.
 * <p>
 * The conversion extracts and combines the chronology and the date-time
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#localDateTime(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoLocalDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date-time, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoLocalDateTime}
 * @see Chronology#localDateTime(TemporalAccessor)
 */
static ChronoLocalDateTime<?> from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoLocalDateTime) {
        return (ChronoLocalDateTime<?>) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoLocalDateTime from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.localDateTime(temporal);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:ChronoLocalDateTime.java

示例5: localDateTime

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
/**
 * Obtains a local date-time in this chronology from another temporal object.
 * <p>
 * This obtains a 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 ChronoLocalDateTime}.
 * <p>
 * The conversion extracts and combines the {@code ChronoLocalDate} and the
 * {@code LocalTime} from the temporal object.
 * 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::localDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the local date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoLocalDateTime#from(TemporalAccessor)
 */
default ChronoLocalDateTime<? extends ChronoLocalDate> localDateTime(TemporalAccessor temporal) {
    try {
        return date(temporal).atTime(LocalTime.from(temporal));
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoLocalDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:Chronology.java


注:本文中的java.time.temporal.TemporalAccessor.getClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。