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


Java TemporalAccessor.query方法代码示例

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


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

示例1: test_chronoNames

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
@Test(dataProvider="chrono_names")
public void test_chronoNames(Chronology chrono, Locale locale, String expected) {
    DateTimeFormatter dtf = new DateTimeFormatterBuilder().appendChronologyText(TextStyle.SHORT)
        .toFormatter(locale);
    String text = dtf.format(chrono.dateNow());
    assertEquals(text, expected);
    TemporalAccessor ta = dtf.parse(text);
    Chronology cal = ta.query(TemporalQueries.chronology());
    assertEquals(cal, chrono);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:TestNonIsoFormatter.java

示例2: validateChrono

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
/**
 * Validates that the temporal has the correct chronology.
 */
private void validateChrono(TemporalAccessor temporal) {
    Objects.requireNonNull(temporal, "temporal");
    Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
    if (temporalChrono != null && IsoChronology.INSTANCE.equals(temporalChrono) == false) {
        throw new DateTimeException("Chronology mismatch, expected: ISO, actual: " + temporalChrono.getId());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:Period.java

示例3: from

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code OffsetDateTime} from a temporal object.
 * <p>
 * This obtains an offset 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 OffsetDateTime}.
 * <p>
 * The conversion will first obtain a {@code ZoneOffset} from the temporal object.
 * It will then try to obtain a {@code LocalDateTime}, falling back to an {@code Instant} if necessary.
 * The result will be the combination of {@code ZoneOffset} with either
 * with {@code LocalDateTime} or {@code Instant}.
 * 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 in queries via method reference, {@code OffsetDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the offset date-time, not null
 * @throws DateTimeException if unable to convert to an {@code OffsetDateTime}
 */
public static OffsetDateTime from(TemporalAccessor temporal) {
    if (temporal instanceof OffsetDateTime) {
        return (OffsetDateTime) temporal;
    }
    try {
        ZoneOffset offset = ZoneOffset.from(temporal);
        LocalDate date = temporal.query(TemporalQueries.localDate());
        LocalTime time = temporal.query(TemporalQueries.localTime());
        if (date != null && time != null) {
            return OffsetDateTime.of(date, time, offset);
        } else {
            Instant instant = Instant.from(temporal);
            return OffsetDateTime.ofInstant(instant, offset);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain OffsetDateTime from TemporalAccessor: " +
                temporal + " of type " + temporal.getClass().getName(), ex);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:OffsetDateTime.java

示例4: from

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code OffsetDateTime} from a temporal object.
 * <p>
 * This obtains an offset 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 OffsetDateTime}.
 * <p>
 * The conversion will first obtain a {@code ZoneOffset} from the temporal object.
 * It will then try to obtain a {@code LocalDateTime}, falling back to an {@code Instant} if necessary.
 * The result will be the combination of {@code ZoneOffset} with either
 * with {@code LocalDateTime} or {@code Instant}.
 * 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 OffsetDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the offset date-time, not null
 * @throws DateTimeException if unable to convert to an {@code OffsetDateTime}
 */
public static OffsetDateTime from(TemporalAccessor temporal) {
    if (temporal instanceof OffsetDateTime) {
        return (OffsetDateTime) temporal;
    }
    try {
        ZoneOffset offset = ZoneOffset.from(temporal);
        LocalDate date = temporal.query(TemporalQueries.localDate());
        LocalTime time = temporal.query(TemporalQueries.localTime());
        if (date != null && time != null) {
            return OffsetDateTime.of(date, time, offset);
        } else {
            Instant instant = Instant.from(temporal);
            return OffsetDateTime.ofInstant(instant, offset);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain OffsetDateTime from TemporalAccessor: " +
                temporal + " of type " + temporal.getClass().getName(), ex);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:41,代码来源:OffsetDateTime.java

示例5: 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:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:ChronoZonedDateTime.java

示例6: from

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code LocalTime} from a temporal object.
 * <p>
 * This obtains a local 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 LocalTime}.
 * <p>
 * The conversion uses the {@link TemporalQueries#localTime()} query, which relies
 * on extracting the {@link ChronoField#NANO_OF_DAY NANO_OF_DAY} field.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code LocalTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the local time, not null
 * @throws DateTimeException if unable to convert to a {@code LocalTime}
 */
public static LocalTime from(TemporalAccessor temporal) {
    Objects.requireNonNull(temporal, "temporal");
    LocalTime time = temporal.query(TemporalQueries.localTime());
    if (time == null) {
        throw new DateTimeException("Unable to obtain LocalTime from TemporalAccessor: " +
                temporal + " of type " + temporal.getClass().getName());
    }
    return time;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:LocalTime.java

示例7: from

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code LocalDate} 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 LocalDate}.
 * <p>
 * The conversion uses the {@link TemporalQueries#localDate()} query, which relies
 * on extracting the {@link ChronoField#EPOCH_DAY EPOCH_DAY} field.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code LocalDate::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the local date, not null
 * @throws DateTimeException if unable to convert to a {@code LocalDate}
 */
public static LocalDate from(TemporalAccessor temporal) {
    Objects.requireNonNull(temporal, "temporal");
    LocalDate date = temporal.query(TemporalQueries.localDate());
    if (date == null) {
        throw new DateTimeException("Unable to obtain LocalDate from TemporalAccessor: " +
                temporal + " of type " + temporal.getClass().getName());
    }
    return date;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:LocalDate.java

示例8: from

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code ZoneId} from a temporal object.
 * <p>
 * This obtains a zone 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 ZoneId}.
 * <p>
 * A {@code TemporalAccessor} represents some form of date and time information.
 * This factory converts the arbitrary temporal object to an instance of {@code ZoneId}.
 * <p>
 * The conversion will try to obtain the zone in a way that favours region-based
 * zones over offset-based zones using {@link TemporalQueries#zone()}.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ZoneId::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zone ID, not null
 * @throws DateTimeException if unable to convert to a {@code ZoneId}
 */
public static ZoneId from(TemporalAccessor temporal) {
    ZoneId obj = temporal.query(TemporalQueries.zone());
    if (obj == null) {
        throw new DateTimeException("Unable to obtain ZoneId from TemporalAccessor: " +
                temporal + " of type " + temporal.getClass().getName());
    }
    return obj;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ZoneId.java

示例9: from

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code ZoneOffset} from a temporal object.
 * <p>
 * This obtains an offset 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 ZoneOffset}.
 * <p>
 * A {@code TemporalAccessor} represents some form of date and time information.
 * This factory converts the arbitrary temporal object to an instance of {@code ZoneOffset}.
 * <p>
 * The conversion uses the {@link TemporalQueries#offset()} query, which relies
 * on extracting the {@link ChronoField#OFFSET_SECONDS OFFSET_SECONDS} field.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ZoneOffset::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zone-offset, not null
 * @throws DateTimeException if unable to convert to an {@code ZoneOffset}
 */
public static ZoneOffset from(TemporalAccessor temporal) {
    Objects.requireNonNull(temporal, "temporal");
    ZoneOffset offset = temporal.query(TemporalQueries.offset());
    if (offset == null) {
        throw new DateTimeException("Unable to obtain ZoneOffset from TemporalAccessor: " +
                temporal + " of type " + temporal.getClass().getName());
    }
    return offset;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:ZoneOffset.java

示例10: 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

示例11: 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:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:ChronoLocalDateTime.java

示例12: from

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code ZoneOffset} from a temporal object.
 * <p>
 * This obtains an offset 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 ZoneOffset}.
 * <p>
 * A {@code TemporalAccessor} represents some form of date and time information.
 * This factory converts the arbitrary temporal object to an instance of {@code ZoneOffset}.
 * <p>
 * The conversion uses the {@link TemporalQueries#offset()} query, which relies
 * on extracting the {@link ChronoField#OFFSET_SECONDS OFFSET_SECONDS} field.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used in queries via method reference, {@code ZoneOffset::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zone-offset, not null
 * @throws DateTimeException if unable to convert to an {@code ZoneOffset}
 */
public static ZoneOffset from(TemporalAccessor temporal) {
    Objects.requireNonNull(temporal, "temporal");
    ZoneOffset offset = temporal.query(TemporalQueries.offset());
    if (offset == null) {
        throw new DateTimeException("Unable to obtain ZoneOffset from TemporalAccessor: " +
                temporal + " of type " + temporal.getClass().getName());
    }
    return offset;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:ZoneOffset.java

示例13: from

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code Chronology} from a temporal object.
 * <p>
 * This obtains a 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 Chronology}.
 * <p>
 * The conversion will obtain the chronology using {@link TemporalQueries#chronology()}.
 * If the specified temporal object does not have a chronology, {@link IsoChronology} is returned.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code Chronology::from}.
 *
 * @param temporal  the temporal to convert, not null
 * @return the chronology, not null
 * @throws DateTimeException if unable to convert to an {@code Chronology}
 */
static Chronology from(TemporalAccessor temporal) {
    Objects.requireNonNull(temporal, "temporal");
    Chronology obj = temporal.query(TemporalQueries.chronology());
    return (obj != null ? obj : IsoChronology.INSTANCE);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:Chronology.java

示例14: from

import java.time.temporal.TemporalAccessor; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code Chronology} from a temporal object.
 * <p>
 * This obtains a 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 Chronology}.
 * <p>
 * The conversion will obtain the chronology using {@link TemporalQueries#chronology()}.
 * If the specified temporal object does not have a chronology, {@link IsoChronology} is returned.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used in queries via method reference, {@code Chronology::from}.
 *
 * @param temporal  the temporal to convert, not null
 * @return the chronology, not null
 * @throws DateTimeException if unable to convert to an {@code Chronology}
 */
static Chronology from(TemporalAccessor temporal) {
    Objects.requireNonNull(temporal, "temporal");
    Chronology obj = temporal.query(TemporalQueries.chronology());
    return (obj != null ? obj : IsoChronology.INSTANCE);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:Chronology.java


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