本文整理了Java中java.util.Date.toInstant()
方法的一些代码示例,展示了Date.toInstant()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Date.toInstant()
方法的具体详情如下:
包路径:java.util.Date
类名称:Date
方法名:toInstant
暂无
代码示例来源:origin: stackoverflow.com
Date input = new Date();
LocalDate date = input.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
代码示例来源:origin: stackoverflow.com
Date input = new Date();
Instant instant = input.toInstant();
代码示例来源:origin: stackoverflow.com
Date input = new Date();
Instant instant = input.toInstant();
Date output = Date.from(instant);
代码示例来源:origin: stackoverflow.com
Date in = new Date();
LocalDateTime ldt = LocalDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault());
代码示例来源:origin: stackoverflow.com
Date input = new Date();
Instant instant = input.toInstant();
ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault());
代码示例来源:origin: stackoverflow.com
Date input = new Date();
Instant instant = input.toInstant();
ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault());
LocalDate date = zdt.toLocalDate();
代码示例来源:origin: stackoverflow.com
Date in = new Date();
LocalDateTime ldt = LocalDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault());
Date out = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
代码示例来源:origin: SonarSource/sonarqube
/**
* Adds a number of days to a date returning a new object.
* The original date object is unchanged.
*
* @param date the date, not null
* @param numberOfDays the amount to add, may be negative
* @return the new date object with the amount added
*/
public static Date addDays(Date date, int numberOfDays) {
return Date.from(date.toInstant().plus(numberOfDays, ChronoUnit.DAYS));
}
代码示例来源: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: lets-blade/blade
/**
* format date to string
*
* @param date date instance
* @param pattern date format pattern
* @return return string date
*/
public static String toString(Date date, String pattern) {
Instant instant = new java.util.Date((date.getTime())).toInstant();
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(pattern));
}
代码示例来源:origin: lets-blade/blade
/**
* format date to string
*
* @param date date instance
* @param pattern date format pattern
* @return return string date
*/
public static String toString(Date date, String pattern) {
Instant instant = new java.util.Date((date.getTime())).toInstant();
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(pattern));
}
代码示例来源:origin: lets-blade/blade
public static String gmtDate(Date date) {
return GMT_FMT.format(LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()).atZone(GMT_ZONE_ID));
}
代码示例来源:origin: square/okhttp
/**
* Returns the last value corresponding to the specified field parsed as an HTTP date, or null if
* either the field is absent or cannot be parsed as a date.
*/
@IgnoreJRERequirement
public @Nullable Instant getInstant(String name) {
Date value = getDate(name);
return value != null ? value.toInstant() : null;
}
代码示例来源: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
/**
* Truncated the analysis date to seconds before comparing it to {@link Issue#creationDate()} is required because
* {@link DefaultIssue#setCreationDate(Date)} does it.
*/
private static long truncateToSeconds(long analysisDate) {
Instant instant = new Date(analysisDate).toInstant();
instant = instant.truncatedTo(ChronoUnit.SECONDS);
return Date.from(instant).getTime();
}
代码示例来源:origin: SonarSource/sonarqube
private static Date truncateMillis(@Nullable Date d) {
if (d == null) {
return null;
}
return Date.from(d.toInstant().truncatedTo(ChronoUnit.SECONDS));
}
}
代码示例来源:origin: SonarSource/sonarqube
private static Date truncateToSecondsImpl(Date d) {
Instant instant = d.toInstant();
instant = instant.truncatedTo(ChronoUnit.SECONDS);
return Date.from(instant);
}
代码示例来源:origin: SonarSource/sonarqube
/**
* Warning: relies on default timezone!
*/
public static String formatDateTime(Date d) {
return formatDateTime(OffsetDateTime.ofInstant(d.toInstant(), ZoneId.systemDefault()));
}
代码示例来源:origin: prestodb/presto
public void queryCreatedEvent(BasicQueryInfo queryInfo)
{
eventListenerManager.queryCreated(
new QueryCreatedEvent(
queryInfo.getQueryStats().getCreateTime().toDate().toInstant(),
createQueryContext(queryInfo.getSession(), queryInfo.getResourceGroupId()),
new QueryMetadata(
queryInfo.getQueryId().toString(),
queryInfo.getSession().getTransactionId().map(TransactionId::toString),
queryInfo.getQuery(),
QUEUED.toString(),
queryInfo.getSelf(),
Optional.empty(),
Optional.empty())));
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void set_created_after_from_created_since() {
Date now = DateUtils.parseDateTime("2013-07-25T07:35:00+0100");
when(clock.instant()).thenReturn(now.toInstant());
when(clock.getZone()).thenReturn(ZoneOffset.UTC);
SearchRequest request = new SearchRequest()
.setCreatedInLast("1y2m3w4d");
assertThat(underTest.create(request).createdAfter().date()).isEqualTo(DateUtils.parseDateTime("2012-04-30T07:35:00+0100"));
assertThat(underTest.create(request).createdAfter().inclusive()).isTrue();
}
内容来源于网络,如有侵权,请联系作者删除!