当前位置: 首页>>代码示例>>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;未经允许,请勿转载。