Java Code Examples for java.time.Instant#from()

The following examples show how to use java.time.Instant#from() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VaultWrappingTemplate.java    From spring-vault with Apache License 2.0 5 votes vote down vote up
private static WrappedMetadata getWrappedMetadata(Map<String, ?> wrapInfo, VaultToken token) {

		TemporalAccessor creation_time = getDate(wrapInfo, "creation_time");
		String path = (String) wrapInfo.get("creation_path");
		Duration ttl = getTtl(wrapInfo);

		return new WrappedMetadata(token, ttl, Instant.from(creation_time), path);
	}
 
Example 2
Source File: FavoriteLogBhv.java    From fess with Apache License 2.0 5 votes vote down vote up
@Override
protected LocalDateTime toLocalDateTime(final Object value) {
    if (value != null) {
        try {
            final Instant instant = Instant.from(DateTimeFormatter.ISO_INSTANT.parse(value.toString()));
            final LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
            return date;
        } catch (final DateTimeParseException e) {
            logger.debug("Invalid date format: {}", value, e);
        }
    }
    return DfTypeUtil.toLocalDateTime(value);
}
 
Example 3
Source File: UserAndTimestamp.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
@JsonCreator
UserAndTimestamp(@JsonProperty("user") String user,
                 @JsonProperty("timestamp") String timestampAsText) {
    this.user = requireNonNull(user, "user");
    this.timestampAsText = requireNonNull(timestampAsText, "timestampAsText");
    timestamp = Instant.from(DateTimeFormatter.ISO_INSTANT.parse(timestampAsText));
}
 
Example 4
Source File: TdTableExportOperatorFactory.java    From digdag with Apache License 2.0 5 votes vote down vote up
private static Instant parseTime(Config params, String key)
{
    try {
        return Instant.ofEpochSecond(
                params.get(key, long.class)
        );
    }
    catch (ConfigException ex) {
        return Instant.from(
                TIME_PARSER
                        .withZone(params.get("timezone", ZoneId.class))
                        .parse(params.get(key, String.class))
        );
    }
}
 
Example 5
Source File: InstantFormatter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Instant parse(String text, Locale locale) throws ParseException {
	if (text.length() > 0 && Character.isDigit(text.charAt(0))) {
		// assuming UTC instant a la "2007-12-03T10:15:30.00Z"
		return Instant.parse(text);
	}
	else {
		// assuming RFC-1123 value a la "Tue, 3 Jun 2008 11:05:30 GMT"
		return Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(text));
	}
}
 
Example 6
Source File: ClickLogBhv.java    From fess with Apache License 2.0 5 votes vote down vote up
@Override
protected LocalDateTime toLocalDateTime(final Object value) {
    if (value != null) {
        try {
            final Instant instant = Instant.from(DateTimeFormatter.ISO_INSTANT.parse(value.toString()));
            final LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
            return date;
        } catch (final DateTimeParseException e) {
            logger.debug("Invalid date format: {}", value, e);
        }
    }
    return DfTypeUtil.toLocalDateTime(value);
}
 
Example 7
Source File: SelfSignedCertificateRuleDelegate.java    From armeria with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param fqdn a fully qualified domain name
 * @param notBefore {@link Certificate} is not valid before this time
 * @param notAfter {@link Certificate} is not valid after this time
 */
public SelfSignedCertificateRuleDelegate(String fqdn,
                                         TemporalAccessor notBefore, TemporalAccessor notAfter) {
    this.fqdn = requireNonNull(fqdn, "fqdn");
    random = null;
    bits = null;
    this.notBefore = Instant.from(requireNonNull(notBefore, "notBefore"));
    this.notAfter = Instant.from(requireNonNull(notAfter, "notAfter"));
}
 
Example 8
Source File: Time.java    From gcp-ingestion with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Attempts to parse a string in format '2011-12-03T10:15:30Z', returning null in case of error.
 */
public static Instant parseAsInstantOrNull(String timestamp) {
  try {
    return Instant.from(DateTimeFormatter.ISO_INSTANT.parse(timestamp));
  } catch (DateTimeParseException | NullPointerException ignore) {
    return null;
  }
}
 
Example 9
Source File: Chronology.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Obtains a {@code ChronoZonedDateTime} in this chronology from another temporal object.
 * <p>
 * This obtains a zoned date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion will first obtain a {@code ZoneId} from the temporal object,
 * falling back to a {@code ZoneOffset} if necessary. It will then try to obtain
 * an {@code Instant}, falling back to a {@code ChronoLocalDateTime} if necessary.
 * The result will be either the combination of {@code ZoneId} or {@code ZoneOffset}
 * with {@code Instant} or {@code ChronoLocalDateTime}.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::zonedDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoZonedDateTime#from(TemporalAccessor)
 */
default ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
    try {
        ZoneId zone = ZoneId.from(temporal);
        try {
            Instant instant = Instant.from(temporal);
            return zonedDateTime(instant, zone);

        } catch (DateTimeException ex1) {
            ChronoLocalDateTimeImpl<?> cldt = ChronoLocalDateTimeImpl.ensureValid(this, localDateTime(temporal));
            return ChronoZonedDateTimeImpl.ofBest(cldt, zone, null);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
Example 10
Source File: VaultKeyValueMetadataTemplate.java    From spring-vault with Apache License 2.0 4 votes vote down vote up
@Nullable
private static Instant toInstant(String date) {

	return StringUtils.hasText(date) ? Instant.from(DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(date)) : null;
}
 
Example 11
Source File: ClockSkewAdjustmentTest.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
private Instant parseSigningDate(String signatureDate) {
    return Instant.from(DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'")
                                         .withZone(ZoneId.of("UTC"))
                                         .parse(signatureDate));
}
 
Example 12
Source File: MCRDateXMLAdapter.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Date unmarshal(String v) throws Exception {
    TemporalAccessor dateTime = MCRISO8601FormatChooser.getFormatter(v, null).parse(v);
    Instant instant = Instant.from(dateTime);
    return Date.from(instant);
}
 
Example 13
Source File: Chronology.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Obtains a {@code ChronoZonedDateTime} in this chronology from another temporal object.
 * <p>
 * This obtains a zoned date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion will first obtain a {@code ZoneId} from the temporal object,
 * falling back to a {@code ZoneOffset} if necessary. It will then try to obtain
 * an {@code Instant}, falling back to a {@code ChronoLocalDateTime} if necessary.
 * The result will be either the combination of {@code ZoneId} or {@code ZoneOffset}
 * with {@code Instant} or {@code ChronoLocalDateTime}.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::zonedDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoZonedDateTime#from(TemporalAccessor)
 */
default ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
    try {
        ZoneId zone = ZoneId.from(temporal);
        try {
            Instant instant = Instant.from(temporal);
            return zonedDateTime(instant, zone);

        } catch (DateTimeException ex1) {
            ChronoLocalDateTimeImpl<?> cldt = ChronoLocalDateTimeImpl.ensureValid(this, localDateTime(temporal));
            return ChronoZonedDateTimeImpl.ofBest(cldt, zone, null);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
Example 14
Source File: Chronology.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Obtains a {@code ChronoZonedDateTime} in this chronology from another temporal object.
 * <p>
 * This obtains a zoned date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion will first obtain a {@code ZoneId} from the temporal object,
 * falling back to a {@code ZoneOffset} if necessary. It will then try to obtain
 * an {@code Instant}, falling back to a {@code ChronoLocalDateTime} if necessary.
 * The result will be either the combination of {@code ZoneId} or {@code ZoneOffset}
 * with {@code Instant} or {@code ChronoLocalDateTime}.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::zonedDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoZonedDateTime#from(TemporalAccessor)
 */
default ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
    try {
        ZoneId zone = ZoneId.from(temporal);
        try {
            Instant instant = Instant.from(temporal);
            return zonedDateTime(instant, zone);

        } catch (DateTimeException ex1) {
            ChronoLocalDateTimeImpl<?> cldt = ChronoLocalDateTimeImpl.ensureValid(this, localDateTime(temporal));
            return ChronoZonedDateTimeImpl.ofBest(cldt, zone, null);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
Example 15
Source File: Chronology.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Obtains a {@code ChronoZonedDateTime} in this chronology from another temporal object.
 * <p>
 * This obtains a zoned date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion will first obtain a {@code ZoneId} from the temporal object,
 * falling back to a {@code ZoneOffset} if necessary. It will then try to obtain
 * an {@code Instant}, falling back to a {@code ChronoLocalDateTime} if necessary.
 * The result will be either the combination of {@code ZoneId} or {@code ZoneOffset}
 * with {@code Instant} or {@code ChronoLocalDateTime}.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::zonedDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoZonedDateTime#from(TemporalAccessor)
 */
default ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
    try {
        ZoneId zone = ZoneId.from(temporal);
        try {
            Instant instant = Instant.from(temporal);
            return zonedDateTime(instant, zone);

        } catch (DateTimeException ex1) {
            ChronoLocalDateTimeImpl<?> cldt = ChronoLocalDateTimeImpl.ensureValid(this, localDateTime(temporal));
            return ChronoZonedDateTimeImpl.ofBest(cldt, zone, null);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
Example 16
Source File: DailySchedulerTest.java    From digdag with Apache License 2.0 4 votes vote down vote up
static Instant instant(String time)
{
    return Instant.from(TIME_FORMAT.parse(time));
}
 
Example 17
Source File: ParameterUtil.java    From styx with Apache License 2.0 4 votes vote down vote up
public static Instant parseDate(String date) {
  return Instant.from(LocalDate.from(
      DateTimeFormatter.ISO_LOCAL_DATE.parse(date))
                          .atStartOfDay(UTC));
}
 
Example 18
Source File: Chronology.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Obtains a {@code ChronoZonedDateTime} in this chronology from another temporal object.
 * <p>
 * This obtains a zoned date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion will first obtain a {@code ZoneId} from the temporal object,
 * falling back to a {@code ZoneOffset} if necessary. It will then try to obtain
 * an {@code Instant}, falling back to a {@code ChronoLocalDateTime} if necessary.
 * The result will be either the combination of {@code ZoneId} or {@code ZoneOffset}
 * with {@code Instant} or {@code ChronoLocalDateTime}.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::zonedDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoZonedDateTime#from(TemporalAccessor)
 */
default ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
    try {
        ZoneId zone = ZoneId.from(temporal);
        try {
            Instant instant = Instant.from(temporal);
            return zonedDateTime(instant, zone);

        } catch (DateTimeException ex1) {
            ChronoLocalDateTimeImpl<?> cldt = ChronoLocalDateTimeImpl.ensureValid(this, localDateTime(temporal));
            return ChronoZonedDateTimeImpl.ofBest(cldt, zone, null);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
Example 19
Source File: DateTimePane.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
/** @return Time currently shown in pane */
public Instant getInstant()
{
    final LocalDateTime local = LocalDateTime.of(date.getValue(), LocalTime.of(hour.getValue(), minute.getValue(), second.getValue()));
    return Instant.from(local.atZone(ZoneId.systemDefault()));
}
 
Example 20
Source File: Chronology.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Obtains a {@code ChronoZonedDateTime} in this chronology from another temporal object.
 * <p>
 * This obtains a zoned date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion will first obtain a {@code ZoneId} from the temporal object,
 * falling back to a {@code ZoneOffset} if necessary. It will then try to obtain
 * an {@code Instant}, falling back to a {@code ChronoLocalDateTime} if necessary.
 * The result will be either the combination of {@code ZoneId} or {@code ZoneOffset}
 * with {@code Instant} or {@code ChronoLocalDateTime}.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::zonedDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoZonedDateTime#from(TemporalAccessor)
 */
default ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
    try {
        ZoneId zone = ZoneId.from(temporal);
        try {
            Instant instant = Instant.from(temporal);
            return zonedDateTime(instant, zone);

        } catch (DateTimeException ex1) {
            ChronoLocalDateTimeImpl<?> cldt = ChronoLocalDateTimeImpl.ensureValid(this, localDateTime(temporal));
            return ChronoZonedDateTimeImpl.ofBest(cldt, zone, null);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}