當前位置: 首頁>>代碼示例>>Java>>正文


Java Instant.from方法代碼示例

本文整理匯總了Java中java.time.Instant.from方法的典型用法代碼示例。如果您正苦於以下問題:Java Instant.from方法的具體用法?Java Instant.from怎麽用?Java Instant.from使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.Instant的用法示例。


在下文中一共展示了Instant.from方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: renderForm

import java.time.Instant; //導入方法依賴的package包/類
/**
 * This presents a form to the end user based on the state of the application. If the customer had previously filled
 * out a form, a pre-filled form will be presented.
 * 
 * @return either a blank or autofilled form
 */
public Form renderForm() {
    if (insecureStorage.containsKey("secureEnvelope") && insecureStorage.containsKey("expirationDateTime")) {
        final String expirationDateTimeString = insecureStorage.get("expirationDateTime");
        final Instant expirationDateTime = Instant.from(formatter.parse(expirationDateTimeString));
        if (Instant.now(clock).isBefore(expirationDateTime)) {
            // a non-expired token is available, present a pre-filled form
            final Form autoFillForm = new Form();
            // present the obfuscated data from insecure storage
            autoFillForm.firstName = insecureStorage.get("firstName");
            autoFillForm.lastName = insecureStorage.get("lastName");
            autoFillForm.emailAddress = insecureStorage.get("emailAddress");
            autoFillForm.autofilled = true;
            return autoFillForm;
        }
        // we've cached the sensitive information, but the token is expired and unusable
        // clear the cache
        insecureStorage.clear();
    }
    // either there is no stored data or it is expired, so render a blank form
    return new Form();
}
 
開發者ID:l0s,項目名稱:fernet-java8,代碼行數:28,代碼來源:Client.java

示例2: adjustTime

import java.time.Instant; //導入方法依賴的package包/類
/**
 * Adjusts the given instant either rounding it up or down.
 *
 * @param instant
 *            the instant to adjust
 * @param zoneId
 *            the time zone
 * @param roundUp
 *            the rounding direction
 * @param firstDayOfWeek
 *            the first day of the week (needed for rounding weeks)
 * @return the adjusted instant
 */
public Instant adjustTime(Instant instant, ZoneId zoneId, boolean roundUp,
                          DayOfWeek firstDayOfWeek) {

    requireNonNull(instant);
    requireNonNull(zoneId);
    requireNonNull(firstDayOfWeek);

    ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, zoneId);
    if (roundUp) {
        zonedDateTime = zonedDateTime.plus(getAmount(), getUnit());
    }

    zonedDateTime = Util.truncate(zonedDateTime, getUnit(), getAmount(),
            firstDayOfWeek);

    return Instant.from(zonedDateTime);
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:31,代碼來源:VirtualGrid.java

示例3: read

import java.time.Instant; //導入方法依賴的package包/類
@Override
public OerGeneralizedTime read(CodecContext context, InputStream inputStream) throws IOException {
  Objects.requireNonNull(context);
  Objects.requireNonNull(inputStream);

  final String timeString = context.read(OerIA5String.class, inputStream).getValue();

  if (timeString.length() != 19 || !timeString.endsWith("Z")) {
    throw new IllegalArgumentException(
        "Interledger GeneralizedTime only supports values in the format 'YYYYMMDDTHHMMSS.fffZ',"
            + " value " + timeString + " is invalid.");
  }

  try {
    final Instant value = Instant.from(generalizedTimeFormatter.parse(timeString));
    return new OerGeneralizedTime(value);
  } catch (DateTimeParseException dtp) {
    throw new IllegalArgumentException(
        "Interledger GeneralizedTime only supports values in the format 'YYYYMMDDTHHMMSS.fffZ', "
            + "value " + timeString + " is invalid.",
        dtp);
  }
}
 
開發者ID:hyperledger,項目名稱:quilt,代碼行數:24,代碼來源:OerGeneralizedTimeCodec.java

示例4: zonedDateTime

import java.time.Instant; //導入方法依賴的package包/類
/**
 * Creates a zoned date-time in this chronology from another date-time object.
 * <p>
 * This creates a date-time in this chronology based on the specified {@code DateTimeAccessor}.
 * <p>
 * This should obtain a {@code ZoneId} using {@link ZoneId#from(DateTimeAccessor)}. The date-time should be
 * obtained by obtaining an {@code Instant}. If that fails, the local date-time should be used.
 * 
 * @param dateTime the date-time object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 */
public ChronoZonedDateTime<C> zonedDateTime(DateTimeAccessor dateTime) {

  try {
    ZoneId zoneId = ZoneId.from(dateTime);
    ChronoDateTimeImpl<C> cldt;
    try {
      Instant instant = Instant.from(dateTime);
      cldt = localInstant(instant, zoneId);
    } catch (DateTimeException ex1) {
      cldt = ensureChronoLocalDateTime(localDateTime(dateTime));
    }
    return ChronoZonedDateTimeImpl.ofBest(cldt, zoneId, null);
  } catch (DateTimeException ex) {
    throw new DateTimeException("Unable to convert DateTimeAccessor to ZonedDateTime: " + dateTime.getClass(), ex);
  }
}
 
開發者ID:kiegroup,項目名稱:optashift-employee-rostering,代碼行數:29,代碼來源:Chrono.java

示例5: onFindAvailableRoomsButtonClicked

import java.time.Instant; //導入方法依賴的package包/類
/**
 * Searches the database for rooms that are available in the given date range.
 */
@FXML
private void onFindAvailableRoomsButtonClicked() {
    // The new date api is great. Converting back and forth, not so much.
    LocalDate checkInDateTemp = checkInDatePicker.getValue();
    LocalDate checkOutDateTemp = checkOutDatePicker.getValue();
    Instant temp1 = Instant.from(checkInDateTemp.atStartOfDay(ZoneId.systemDefault()));
    Instant temp2 = Instant.from(checkOutDateTemp.atStartOfDay(ZoneId.systemDefault()));
    Date checkInDate = Date.from(temp1);
    Date checkOutDate = Date.from(temp2);

    // Clear any existing results
    roomSearchResults.clear();
    selectedRooms.clear();

    // Get the new results
    BookingService bookingService = new BookingService();
    roomSearchResults.addAll(bookingService.getRoomTypesAvailable(checkInDate, checkOutDate));
}
 
開發者ID:maillouxc,項目名稱:git-rekt,代碼行數:22,代碼來源:BrowseRoomsScreenController.java

示例6: expiredTtl

import java.time.Instant; //導入方法依賴的package包/類
@Test
public final void expiredTtl() {
    // given
    final Token token = Token.fromString(
            "gAAAAAAdwJ6xAAECAwQFBgcICQoLDA0OD3HkMATM5lFqGaerZ-fWPAl1-szkFVzXTuGb4hR8AKtwcaX1YdykRtfsH-p1YsUD2Q==");
    final Key key = new Key("cw_0x689RpI-jtRR7oE8h_eQsKImvJapLeSbXpwF4e4=");
    now = Instant.from(formatter.parse("1985-10-26T01:21:31-07:00"));

    // when
    thrown.expect(TokenValidationException.class);
    thrown.reportMissingExceptionWithMessage("Token should be expired: " + token);
    token.validateAndDecrypt(key, validator);

    // then (nothing)
}
 
開發者ID:l0s,項目名稱:fernet-java8,代碼行數:16,代碼來源:FernetTest.java

示例7: toMillis

import java.time.Instant; //導入方法依賴的package包/類
private static long toMillis(String date) {
	TemporalAccessor temporalAccessor = DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse(date);
	LocalDateTime localDateTime = LocalDateTime.from(temporalAccessor);
	ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, ZoneId.systemDefault());
	Instant instant = Instant.from(zonedDateTime);
	return instant.toEpochMilli();
}
 
開發者ID:DescartesResearch,項目名稱:Pet-Supply-Store,代碼行數:8,代碼來源:TrainingSynchronizer.java

示例8: getLocalImageTimestamp

import java.time.Instant; //導入方法依賴的package包/類
private static Instant getLocalImageTimestamp(String imageName) {
	// Use docker inspect
	try {
		String isoDatetime = DefaultCommandRunner.INSTANCE.runCommandAndCaptureOutput("docker", "inspect", "-f", "{{.Created}}", imageName);
		return Instant.from(DateTimeFormatter.ISO_ZONED_DATE_TIME.parse(isoDatetime));
	}
	catch (RuntimeException e) {
		log.debug("Could not determine timestamp of local image [" + imageName + "], assuming it doesn't exist on the local docker host", e);
		return null;
	}
}
 
開發者ID:swissquote,項目名稱:carnotzet,代碼行數:12,代碼來源:DockerRegistry.java

示例9: asInstant

import java.time.Instant; //導入方法依賴的package包/類
private static Instant asInstant(final String timestamp) {
    return Instant.from(DateTimeFormatter.ISO_DATE_TIME.parse(timestamp));
}
 
開發者ID:NHS-digital-website,項目名稱:hippo,代碼行數:4,代碼來源:ExpectedTestDataProvider.java

示例10: zonedDateTime

import java.time.Instant; //導入方法依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:40,代碼來源:Chronology.java


注:本文中的java.time.Instant.from方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。