热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

java.time.temporal.TemporalQueries.localDate()方法的使用及代码示例

本文整理了Java中java.time.temporal.TemporalQueries.localDate()方法的一些代码示例,展示了TemporalQ

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

TemporalQueries.localDate介绍

[英]A query for LocalDate returning null if not found.

This returns a TemporalQuery that can be used to query a temporal object for the local date. The query will return null if the temporal object cannot supply a local date.

The query implementation examines the ChronoField#EPOCH_DAYfield and uses it to create a LocalDate.
[中]如果找不到LocalDate,则返回null的查询。
这将返回一个临时查询,可用于查询本地日期的临时对象。如果时态对象不能提供本地日期,查询将返回null。
查询实现检查ChronoField#EPOCH_DAYfield并使用它创建LocalDate。

代码示例

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

final LocalDate expectedDate = ((Temporal) expectedValue).query( TemporalQueries.localDate() );
final LocalTime expectedTime = ((Temporal) expectedValue).query( TemporalQueries.localTime() );
final ZoneId expectedZOneId= ((Temporal) expectedValue).query( TemporalQueries.zone() );
LocalDate actualDate = ((Temporal) actualValue).query( TemporalQueries.localDate() );
LocalTime actualTime = ((Temporal) actualValue).query( TemporalQueries.localTime() );
ZoneId actualZOneId= ((Temporal) actualValue).query( TemporalQueries.zone() );

代码示例来源:origin: org.threeten/threeten-extra

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.localDate()) {
return (R) isoDate;
}
return super.query(query);
}

代码示例来源:origin: com.nhl.link.rest/link-rest-base

private Optional getLocalDate(TemporalAccessor parsed) {
return Optional.ofNullable(parsed.query(TemporalQueries.localDate()));
}

代码示例来源:origin: agrestio/agrest

private Optional getLocalDate(TemporalAccessor parsed) {
return Optional.ofNullable(parsed.query(TemporalQueries.localDate()));
}

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

/**
* Queries this date-time using the specified query.
*


* This queries this date-time using the specified query strategy object.
* The {@code TemporalQuery} object defines the logic to be used to
* obtain the result. Read the documentation of the query to understand
* what the result of this method will be.
*


* The result of this method is obtained by invoking the
* {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
* specified query passing {@code this} as the argument.
*
* @param the type of the result
* @param query the query to invoke, not null
* @return the query result, null may be returned (defined by the query)
* @throws DateTimeException if unable to query (defined by the query)
* @throws ArithmeticException if numeric overflow occurs (defined by the query)
*/
@SuppressWarnings("unchecked")
@Override // override for Javadoc
public R query(TemporalQuery query) {
if (query == TemporalQueries.localDate()) {
return (R) toLocalDate();
}
return super.query(query);
}

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

/**
* Queries this date using the specified query.
*


* This queries this date using the specified query strategy object.
* The {@code TemporalQuery} object defines the logic to be used to
* obtain the result. Read the documentation of the query to understand
* what the result of this method will be.
*


* The result of this method is obtained by invoking the
* {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
* specified query passing {@code this} as the argument.
*
* @param the type of the result
* @param query the query to invoke, not null
* @return the query result, null may be returned (defined by the query)
* @throws DateTimeException if unable to query (defined by the query)
* @throws ArithmeticException if numeric overflow occurs (defined by the query)
*/
@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.localDate()) {
return (R) this;
}
return super.query(query);
}

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

/**
* Obtains an instance of {@code LocalDate} from a temporal object.
*


* A {@code TemporalAccessor} represents some form of date and time information.
* This factory converts the arbitrary temporal object to an instance of {@code LocalDate}.
*


* The conversion uses the {@link TemporalQueries#localDate()} query, which relies
* on extracting the {@link ChronoField#EPOCH_DAY EPOCH_DAY} field.
*


* 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) {
LocalDate date = temporal.query(TemporalQueries.localDate());
if (date == null) {
throw new DateTimeException("Unable to obtain LocalDate from TemporalAccessor: " +
temporal + ", type " + temporal.getClass().getName());
}
return date;
}

代码示例来源:origin: eXparity/hamcrest-date

@Override
protected boolean matchesSafely(final T actual, final Description mismatchDesc) {
if (!this.adapter.asTemporal(actual, zone).query(localDate()).isLeapYear()) {
mismatchDesc.appendText("the date " + this.formatter.describe(actual) + " is not a leap year");
return false;
} else {
return true;
}
}

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

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.ERAS;
}
if (query == TemporalQueries.chronology() || query == TemporalQueries.zone() ||
query == TemporalQueries.zoneId() || query == TemporalQueries.offset() ||
query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) {
return null;
}
return query.queryFrom(this);
}

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

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.ERAS;
}
if (query == TemporalQueries.chronology() || query == TemporalQueries.zone() ||
query == TemporalQueries.zoneId() || query == TemporalQueries.offset() ||
query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) {
return null;
}
return query.queryFrom(this);
}

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

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.ERAS;
}
if (query == TemporalQueries.chronology() || query == TemporalQueries.zone() ||
query == TemporalQueries.zoneId() || query == TemporalQueries.offset() ||
query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) {
return null;
}
return query.queryFrom(this);
}

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

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.ERAS;
}
if (query == TemporalQueries.chronology() || query == TemporalQueries.zone() ||
query == TemporalQueries.zoneId() || query == TemporalQueries.offset() ||
query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) {
return null;
}
return query.queryFrom(this);
}

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

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.ERAS;
}
if (query == TemporalQueries.chronology() || query == TemporalQueries.zone() ||
query == TemporalQueries.zoneId() || query == TemporalQueries.offset() ||
query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) {
return null;
}
return query.queryFrom(this);
}

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

query == TemporalQueries.localDate()) {
return null;

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

} else if (query == TemporalQueries.precision()) {
return (R) MONTHS;
} else if (query == TemporalQueries.localDate() || query == TemporalQueries.localTime() ||
query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
return null;

代码示例来源:origin: youtongluan/sumk

@Override
public SumkDate queryFrom(TemporalAccessor temporal) {
if (temporal instanceof LocalDateTime) {
return SumkDate.of((LocalDateTime) temporal);
} else if (temporal instanceof ZonedDateTime) {
LocalDateTime dt = ((ZonedDateTime) temporal).toLocalDateTime();
return SumkDate.of(dt);
} else if (temporal instanceof OffsetDateTime) {
LocalDateTime dt = ((OffsetDateTime) temporal).toLocalDateTime();
return SumkDate.of(dt);
}
LocalDate date = temporal.query(TemporalQueries.localDate());
LocalTime time = temporal.query(TemporalQueries.localTime());
if (date == null && time == null) {
return null;
}
return SumkDate.of(date, time);
}

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

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.chronology()) {
return (R) getChronology();
} else if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.DAYS;
} else if (query == TemporalQueries.localDate()) {
return (R) LocalDate.ofEpochDay(toEpochDay());
} else if (query == TemporalQueries.localTime() || query == TemporalQueries.zone() ||
query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
return null;
}
return super.query(query);
}

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

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.zoneId()) {
return (R) zone;
} else if (query == TemporalQueries.chronology()) {
return (R) chrono;
} else if (query == TemporalQueries.localDate()) {
return date != null ? (R) LocalDate.from(date) : null;
} else if (query == TemporalQueries.localTime()) {
return (R) time;
} else if (query == TemporalQueries.zone() || query == TemporalQueries.offset()) {
return query.queryFrom(this);
} else if (query == TemporalQueries.precision()) {
return null; // not a complete date/time
}
// inline TemporalAccessor.super.query(query) as an optimization
// non-JDK classes are not permitted to make this optimization
return query.queryFrom(this);
}

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

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.chronology()) {
return (R) getChronology();
} else if (query == TemporalQueries.precision()) {
return (R) NANOS;
} else if (query == TemporalQueries.localDate()) {
return (R) LocalDate.ofEpochDay(toLocalDate().toEpochDay());
} else if (query == TemporalQueries.localTime()) {
return (R) toLocalTime();
} else if (query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
return null;
}
return super.query(query);
}

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

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.zoneId() || query == TemporalQueries.zone()) {
return (R) getZone();
} else if (query == TemporalQueries.chronology()) {
return (R) toLocalDate().getChronology();
} else if (query == TemporalQueries.precision()) {
return (R) NANOS;
} else if (query == TemporalQueries.offset()) {
return (R) getOffset();
} else if (query == TemporalQueries.localDate()) {
return (R) LocalDate.ofEpochDay(toLocalDate().toEpochDay());
} else if (query == TemporalQueries.localTime()) {
return (R) toLocalTime();
}
return super.query(query);
}

推荐阅读
  • 本文深入探讨了 Java 中的 Serializable 接口,解释了其实现机制、用途及注意事项,帮助开发者更好地理解和使用序列化功能。 ... [详细]
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • 实体映射最强工具类:MapStruct真香 ... [详细]
  • 深入解析Redis内存对象模型
    本文详细介绍了Redis内存对象模型的关键知识点,包括内存统计、内存分配、数据存储细节及优化策略。通过实际案例和专业分析,帮助读者全面理解Redis内存管理机制。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 本文介绍了如何通过 Maven 依赖引入 SQLiteJDBC 和 HikariCP 包,从而在 Java 应用中高效地连接和操作 SQLite 数据库。文章提供了详细的代码示例,并解释了每个步骤的实现细节。 ... [详细]
  • andr ... [详细]
  • 并发编程:深入理解设计原理与优化
    本文探讨了并发编程中的关键设计原则,特别是Java内存模型(JMM)的happens-before规则及其对多线程编程的影响。文章详细介绍了DCL双重检查锁定模式的问题及解决方案,并总结了不同处理器和内存模型之间的关系,旨在为程序员提供更深入的理解和最佳实践。 ... [详细]
  • MySQL索引详解与优化
    本文深入探讨了MySQL中的索引机制,包括索引的基本概念、优势与劣势、分类及其实现原理,并详细介绍了索引的使用场景和优化技巧。通过具体示例,帮助读者更好地理解和应用索引以提升数据库性能。 ... [详细]
  • MySQL DateTime 类型数据处理及.0 尾数去除方法
    本文介绍如何在 MySQL 中处理 DateTime 类型的数据,并解决获取数据时出现的.0尾数问题。同时,探讨了不同场景下的解决方案,确保数据格式的一致性和准确性。 ... [详细]
  • 深入解析TCP/IP五层协议
    本文详细介绍了TCP/IP五层协议模型,包括物理层、数据链路层、网络层、传输层和应用层。每层的功能及其相互关系将被逐一解释,帮助读者理解互联网通信的原理。此外,还特别讨论了UDP和TCP协议的特点以及三次握手、四次挥手的过程。 ... [详细]
  • FinOps 与 Serverless 的结合:破解云成本难题
    本文探讨了如何通过 FinOps 实践优化 Serverless 应用的成本管理,提出了首个 Serverless 函数总成本估计模型,并分享了多种有效的成本优化策略。 ... [详细]
  • 选择适合生产环境的Docker存储驱动
    本文旨在探讨如何在生产环境中选择合适的Docker存储驱动,并详细介绍不同Linux发行版下的配置方法。通过参考官方文档和兼容性矩阵,提供实用的操作指南。 ... [详细]
  • 本文探讨了使用C#在SQL Server和Access数据库中批量插入多条数据的性能差异。通过具体代码示例,详细分析了两种数据库的执行效率,并提供了优化建议。 ... [详细]
  • 本文介绍如何使用MFC和ADO技术调用SQL Server中的存储过程,以查询指定小区在特定时间段内的通话统计数据。通过用户界面选择小区ID、开始时间和结束时间,系统将计算并展示小时级的通话量、拥塞率及半速率通话比例。 ... [详细]
author-avatar
小邵Bans_530
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有