- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中java.time.ZonedDateTime.toLocalDate()
方法的一些代码示例,展示了ZonedDateTime.toLocalDate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonedDateTime.toLocalDate()
方法的具体详情如下:
包路径:java.time.ZonedDateTime
类名称:ZonedDateTime
方法名:toLocalDate
[英]Gets the LocalDate part of this date-time.
This returns a LocalDate with the same year, month and day as this date-time.
[中]获取此日期时间的LocalDate部分。
这将返回一个LocalDate,其年份、月份和日期与此日期时间相同。
代码示例来源:origin: spring-projects/spring-framework
@Override
public LocalDate convert(ZonedDateTime source) {
return source.toLocalDate();
}
}
代码示例来源:origin: stackoverflow.com
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
public class DateUtils {
public static Date asDate(LocalDate localDate) {
return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
}
public static Date asDate(LocalDateTime localDateTime) {
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}
public static LocalDate asLocalDate(Date date) {
return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDate();
}
public static LocalDateTime asLocalDateTime(Date date) {
return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public LocalDate convert(Calendar source) {
return calendarToZonedDateTime(source).toLocalDate();
}
}
代码示例来源:origin: org.springframework/spring-context
@Override
public LocalDate convert(Calendar source) {
return calendarToZonedDateTime(source).toLocalDate();
}
}
代码示例来源:origin: neo4j/neo4j
@Override
LocalDate getDatePart()
{
return value.toLocalDate();
}
代码示例来源:origin: org.springframework/spring-context
@Override
public LocalDate convert(ZonedDateTime source) {
return source.toLocalDate();
}
}
代码示例来源:origin: stackoverflow.com
Date input = new Date();
Instant instant = input.toInstant();
ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault());
LocalDate date = zdt.toLocalDate();
代码示例来源:origin: jenkinsci/jenkins
/**
* Compute the number of calendar days elapsed since the given date.
* As it's only the calendar days difference that matter, "11.00pm" to "2.00am the day after" returns 1,
* even if there are only 3 hours between. As well as "10am" to "2pm" both on the same day, returns 0.
*/
@Restricted(NoExternalUse.class)
public static long daysBetween(@Nonnull Date a, @Nonnull Date b){
LocalDate aLocal = a.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate bLocal = b.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
return ChronoUnit.DAYS.between(aLocal, bLocal);
}
代码示例来源:origin: SonarSource/sonarqube
/**
* Warning: relies on default timezone!
*/
public static String formatDate(Date d) {
return d.toInstant().atZone(ZoneId.systemDefault()).toLocalDate().toString();
}
代码示例来源:origin: SonarSource/sonarqube
/**
* Warning: relies on default timezone!
*
* @since 7.6
*/
public static String formatDate(Instant d) {
return d.atZone(ZoneId.systemDefault()).toLocalDate().toString();
}
代码示例来源:origin: jooby-project/jooby
private static LocalDate parse(final DateTimeFormatter formatter, final String value) {
try {
Instant epoch = Instant.ofEpochMilli(Long.parseLong(value));
ZonedDateTime zonedDate = epoch.atZone(
Optional.ofNullable(formatter.getZone())
.orElse(ZoneId.systemDefault())
);
return zonedDate.toLocalDate();
} catch (NumberFormatException ex) {
return LocalDate.parse(value, formatter);
}
}
代码示例来源:origin: apache/nifi
private static LocalDate getLocalDateFromEpochTime(String fieldName, Object coercedValue) {
Long date = DataTypeUtils.toLong(coercedValue, fieldName);
return Instant.ofEpochMilli(date).atZone(ZoneId.systemDefault()).toLocalDate();
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public LocalDate decode(final BsonReader reader, final DecoderContext decoderContext) {
return Instant.ofEpochMilli(validateAndReadDateTime(reader)).atZone(ZoneOffset.UTC).toLocalDate();
}
代码示例来源:origin: jtablesaw/tablesaw
public static int pack(Date date) {
return pack(date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
}
代码示例来源:origin: blynkkk/blynk-server
@Override
public void buildDynamicSection(StringBuilder sb, ZoneId zoneId) {
sb.append("Period: ").append(getDurationLabel());
addReportSpecificAtTime(sb, zoneId);
if (durationType == ReportDurationType.CUSTOM) {
sb.append("<br>");
ZonedDateTime date;
date = getZonedFromTs(startTs, zoneId);
sb.append("Start date: ").append(date.toLocalDate()).append("<br>");
date = ZonedDateTime.ofInstant(Instant.ofEpochMilli(endTs), zoneId);
sb.append("End date: ").append(date.toLocalDate()).append("<br>");
}
}
代码示例来源:origin: stackoverflow.com
ZoneId zoneId_Norway = ZoneId.of( "Europe/Oslo" );
ZonedDateTime zdt_Norway = ZonedDateTime.of( 1985 , 1 , 1 , 3 , 2 , 1 , 0 , zoneId_Norway );
ZoneId zoneId_NewYork = ZonedId.of( "America/New_York" );
ZonedDateTime zdt_NewYork = zdt_Norway.withZoneSameInstant( zoneId_NewYork );
ZonedDateTime zdt_Utc = zdt_Norway.withZoneSameInstant( ZoneOffset.UTC ); // Or, next line is similar.
Instant instant = zdt_Norway.toInstant(); // Instant is always in UTC.
LocalDate localDate_Norway = zdt_Norway.toLocalDate();
代码示例来源:origin: SonarSource/sonarqube
private static String dateTimeToDate(String timestamp, TimeZone timeZone) {
Date date = parseDateTime(timestamp);
return date.toInstant().atZone(timeZone.toZoneId()).toLocalDate().toString();
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public <X> LocalDate wrap(X value, WrapperOptions options) {
if ( value == null ) {
return null;
}
if ( LocalDate.class.isInstance( value ) ) {
return (LocalDate) value;
}
if ( Timestamp.class.isInstance( value ) ) {
final Timestamp ts = (Timestamp) value;
return LocalDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() ).toLocalDate();
}
if ( Long.class.isInstance( value ) ) {
final Instant instant = Instant.ofEpochMilli( (Long) value );
return LocalDateTime.ofInstant( instant, ZoneId.systemDefault() ).toLocalDate();
}
if ( Calendar.class.isInstance( value ) ) {
final Calendar calendar = (Calendar) value;
return LocalDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() ).toLocalDate();
}
if ( Date.class.isInstance( value ) ) {
if ( java.sql.Date.class.isInstance( value ) ) {
return ((java.sql.Date) value).toLocalDate();
}
else {
return Instant.ofEpochMilli( ((Date) value).getTime() ).atZone( ZoneId.systemDefault() ).toLocalDate();
}
}
throw unknownWrap( value.getClass() );
}
代码示例来源:origin: graphhopper/graphhopper
private boolean isValidOn(EdgeIteratorState edge, long instant) {
GtfsStorage.EdgeType edgeType = flagEncoder.getEdgeType(edge.getFlags());
if (edgeType == GtfsStorage.EdgeType.BOARD || edgeType == GtfsStorage.EdgeType.ALIGHT) {
final int validityId = flagEncoder.getValidityId(edge.getFlags());
final GtfsStorage.Validity validity = realtimeFeed.getValidity(validityId);
final int trafficDay = (int) ChronoUnit.DAYS.between(validity.start, Instant.ofEpochMilli(instant).atZone(validity.zoneId).toLocalDate());
return trafficDay >= 0 && validity.validity.get(trafficDay);
} else {
return true;
}
}
代码示例来源:origin: blynkkk/blynk-server
public boolean isTickTime(ZonedDateTime currentDateTime) {
LocalDate userDate = currentDateTime.withZoneSameInstant(tzName).toLocalDate();
int dayOfWeek = userDate.getDayOfWeek().getValue();
return ArrayUtil.contains(days, dayOfWeek);
}
我创建了两个 ZonedDateTime 对象,我认为它们应该相等: public static void main(String[] args) { ZoneId zid = ZoneId.
假设我有一个 ZonedDateTime: ZonedDateTime zonedDateTime = ZonedDateTime.of(LocalDateTime.now(), ZoneI
给定以下单元测试: @Test public void zonedDateTimeCorrectlyRestoresItself() { // construct a new instance
我正在尝试将 ZonedDateTime 与以下代码进行比较: val now = ZonedDateTime.now() val query = for { x Timestamp.from(
我最近迁移到 Java 8,希望能更轻松地处理本地和分区时间。 但是,在我看来,在解析简单日期时,我遇到了一个简单的问题。 public static ZonedDateTime convertirA
您好,我已经搜索过类似的问题,但没有成功。我正在调用一个 ws,它将一个 token 发回给我,当它是有效的示例时: { "token": ..., "notBefore":"Thu 21
我有一个 ZonedDateTime 对象,我想根据给定的区域设置对其进行格式化。 IE。在美国,我希望格式为“M-dd-yy”,但在英国则应为“dd-M-yy”。 在给定的语言环境下执行此操作的最佳
在比较 ZonedDateTimes 时,使用 和 == 并不总是与使用 .isBefore、.isAfter 和 isEqual 相同,如下面的 Kotlin 示例所示: import java.
我有以下功能 public String getDateAndTimeInUserFormat(String value, DateTimeFormat inputFormat) { retu
我的时间以毫秒为单位,我需要将其转换为 ZonedDateTime 对象。 我有以下代码 long m = System.currentTimeMillis(); LocalDateTime d =
我尝试将字符串转换为 ZonedDateTime。这是我的代码: String startTime = "Wed Mar 21 2018 08:00:00 GMT 0330 (IRST)"; Stri
在比较 ZonedDateTimes 时,使用 和 == 并不总是与使用 .isBefore、.isAfter 和 isEqual 相同,如下面的 Kotlin 示例所示: import java.
我正在尝试获取存储为 UTC 的日期时间并将其转换为给定时区的日期时间。据我所知,ZonedDateTime 是正确的(“美国/芝加哥”比 UTC 晚 5 小时),但 DateTimeFormatte
我需要将字符串 2020-04-15T23:00:00+0000 转换为 ZonedDateTime。我尝试了以下方法,但没有成功: DateTimeFormatter formatter = Dat
如何将已设置的 ZonedDateTime 时间更改为“java.time.LocalTime.MIN”或“java.time.LocalTime.MAX”? ZonedDateTime date =
我正在尝试将字符串转换为 ZonedDateTime。 我尝试过以下操作: SimpleDateFormat zonedDateTimeFormat = new SimpleDateFormat("y
我目前正在研究日期在英国夏令时间之内和之外时的 ZonedDateTime 行为。 英国夏令时间从 3 月 25 日开始,增加一小时 (+1)。 我创建了几个 ZonedDateTime 实例(UTC
ZonedDateTime zdt3 = ZonedDateTime.parse("1999-09-09 09:09:09.999", DateTimeFormatter.of
我有一个返回年、月、日和小时的 DTO。因此将值从 DTO 传递到 ZonedDateTime.of 方法。此处,时间显示为太平洋标准时间上午 10 点。因此,尝试将其转换为 UTC。 当传递月份为
String ip="2011-05-01T06:47:35.422-05:00"; ZonedDateTime mzt = ZonedDateTime.parse(ip).toInstant().a
我是一名优秀的程序员,十分优秀!