Example usage for java.util Date toInstant

List of usage examples for java.util Date toInstant

Introduction

In this page you can find the example usage for java.util Date toInstant.

Prototype

public Instant toInstant() 

Source Link

Document

Converts this Date object to an Instant .

Usage

From source file:com.intuit.wasabi.api.pagination.filters.FilterUtil.java

/**
 * Converts the old {@link Date} to a new {@link OffsetDateTime}, taking the UTC offset into account.
 *
 * @param date the date to convert//from ww  w .  ja  v  a  2s.c o  m
 * @return the converted date
 */
public static OffsetDateTime convertDateToOffsetDateTime(Date date) {
    return OffsetDateTime.ofInstant(date.toInstant(), ZoneId.of("UTC"));
}

From source file:org.hippoecm.frontend.plugins.standards.datetime.DateTimePrinter.java

static DateTimePrinter of(final Date date) {
    return date != null ? of(date.toInstant()) : EmptyDateTimePrinter.INSTANCE;
}

From source file:org.openhab.binding.gardena.internal.util.DateUtils.java

/**
 * Converts a string to a Date, trying different date formats used by Gardena.
 *///from ww w.  j a v a  2  s  .c  o  m
public static Date parseToDate(String text) {
    if (StringUtils.isNotBlank(text)) {
        Date parsedDate = null;
        for (String dateFormat : dateFormats) {
            try {
                parsedDate = new SimpleDateFormat(dateFormat).parse(text);
                ZonedDateTime gmt = ZonedDateTime.ofInstant(parsedDate.toInstant(), ZoneOffset.UTC);
                LocalDateTime here = gmt.withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime();
                parsedDate = Date.from(here.toInstant(ZoneOffset.UTC));
                break;
            } catch (ParseException ex) {
            }
        }
        if (parsedDate == null) {
            LOGGER.error("Can't parse date {}", text);
        }
        return parsedDate;
    } else {
        return null;
    }

}

From source file:com.hotelbeds.hotelapimodel.auto.util.AssignUtils.java

public static LocalDate getLocalDate(final Date date) {
    return date != null ? date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null;
}

From source file:io.manasobi.utils.DateUtils.java

public static LocalDateTime convertToDateTime(long timeMillis) {
    Date date = new Date(timeMillis);
    return date.toInstant().atZone(ZoneId.of("Asia/Seoul")).toLocalDateTime();
}

From source file:com.hubrick.vertx.s3.signature.AWS4SignatureBuilder.java

public static AWS4SignatureBuilder builder(final Date date, final String region, final String service) {
    return builder(ZonedDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()), region, service);
}

From source file:com.ikanow.aleph2.data_model.utils.TimeUtils.java

/** Returns a date from a human readable date - can only be in the future
 * @param human_readable_date - the date expressed in words, eg "next wednesday".. Uses some simple regexes (1h,d, 1month etc), and Natty (try examples http://natty.joestelmach.com/try.jsp#)
 * @param base_date - for relative date, locks the date to this origin
 * @return the machine readable date, or an error
 *///from  www.  j  a va2  s  . c o  m
public static Validation<String, Date> getForwardSchedule(final String human_readable_date,
        Optional<Date> base_date) {
    final Date adjusted_date = base_date.orElse(new Date());
    return _adjustments.stream()
            .map(adjust -> Date.from(adjusted_date.toInstant().plus(adjust._1(), adjust._2()))) // (adjust the date by the increasing adjustment)
            .map(adjusted -> getSchedule(human_readable_date, Optional.of(adjusted)))
            .filter(parsed -> parsed.isSuccess())
            .filter(parsed -> parsed.success().getTime() >= adjusted_date.getTime()).findFirst()
            .orElse(Validation
                    .fail(ErrorUtils.get(ErrorUtils.INVALID_DATETIME_FORMAT_PAST, human_readable_date)));
}

From source file:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java

public static LocalDate toLocalDate(Date date) throws BusinessException {
    return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}

From source file:org.sonar.server.issue.IssueFieldsSetter.java

private static Date truncateMillis(@Nullable Date d) {
    if (d == null) {
        return null;
    }/*from   w  w  w.j a v  a  2  s.c  om*/
    return Date.from(d.toInstant().truncatedTo(ChronoUnit.SECONDS));
}

From source file:com.esri.geoportal.commons.csw.client.impl.Client.java

/**
 * Formats ISO date.//from   w  ww  . j  a  v a2  s  . c  o m
 * @param date date to format
 * @return ISO date
 */
private static String formatIsoDate(Date date) {
    ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
    return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(zonedDateTime);
}