Date input = new Date(); LocalDate date = input.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
Date input = new Date(); Instant instant = input.toInstant();
Date input = new Date(); Instant instant = input.toInstant(); Date output = Date.from(instant);
Date in = new Date(); LocalDateTime ldt = LocalDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault());
Date input = new Date(); Instant instant = input.toInstant(); ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault());
Date input = new Date(); Instant instant = input.toInstant(); ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault()); LocalDate date = zdt.toLocalDate();
Date in = new Date(); LocalDateTime ldt = LocalDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault()); Date out = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
/** * 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)); }
/** * 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); }
/** * 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)); }
/** * 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)); }
public static String gmtDate(Date date) { return GMT_FMT.format(LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()).atZone(GMT_ZONE_ID)); }
/** * 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; }
/** * Warning: relies on default timezone! */ public static String formatDate(Date d) { return d.toInstant().atZone(ZoneId.systemDefault()).toLocalDate().toString(); }
/** * 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(); }
private static Date truncateMillis(@Nullable Date d) { if (d == null) { return null; } return Date.from(d.toInstant().truncatedTo(ChronoUnit.SECONDS)); } }
private static Date truncateToSecondsImpl(Date d) { Instant instant = d.toInstant(); instant = instant.truncatedTo(ChronoUnit.SECONDS); return Date.from(instant); }
/** * Warning: relies on default timezone! */ public static String formatDateTime(Date d) { return formatDateTime(OffsetDateTime.ofInstant(d.toInstant(), ZoneId.systemDefault())); }
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()))); }
@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(); }