java.util.Date#from ( )源码实例Demo

下面列出了java.util.Date#from ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: bouncr   文件: PreSignInResource.java
@Decision(POST)
public OidcSession post(RestContext context) {
    String oidcSessionId = UUID.randomUUID().toString();
    OidcSession oidcSession = OidcSession.create(config.getSecureRandom());
    storeProvider.getStore(OIDC_SESSION).write(oidcSessionId, oidcSession);

    Cookie cookie = Cookie.create(COOKIE_NAME, oidcSessionId);
    ZoneId zone = ZoneId.systemDefault();
    Date expires = Date.from(
            ZonedDateTime.of(LocalDateTime.now()
                    .plusSeconds(config.getOidcSessionExpires()), zone)
                    .toInstant());
    cookie.setExpires(expires);
    cookie.setPath("/");
    context.setHeaders(Headers.of("Set-Cookie", cookie.toHttpString()));

    return oidcSession;
}
 
@Override
public Date convertToDatabaseColumn(LocalDateTime localDateTime) {

	if(localDateTime != null) {
		Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
		return Date.from(instant);
	}
	
	return null;
	
}
 
源代码3 项目: pentaho-kettle   文件: ValueMetaStringTest.java
@Test
public void testGetDateWithoutConversionMask() throws KettleValueException, ParseException {
  Calendar date = new GregorianCalendar( 2017, 9, 20 ); // month 9 = Oct
  String value = "2017/10/20 00:00:00.000";
  ValueMetaInterface stringValueMeta = new ValueMetaString( "test" );

  Date expected = Date.from( date.toInstant() );
  Date result = stringValueMeta.getDate( value );
  assertEquals( expected, result );
}
 
源代码4 项目: sakai   文件: DateFormatterUtil.java
/**
 * Parse the date string input using the ISO_ZONED_DATE_TIME format such as '2017-12-03T10:15:30+01:00[Europe/Paris]'.
 * 
 * @param inputDate
 *            The string that needs to be parsed.
 * 
 * @throws Exception 
 * 			If not a valid date compared to ISO_ZONED_DATE_TIME format
 */
public static Date parseISODate(final String inputDate) {
	Date convertedDate = null;

	try {
		LocalDateTime ldt = LocalDateTime.parse(inputDate, isoFormatter);
		convertedDate = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
	} catch (Exception  e) {
		log.warn("Error parsing the date {} using the ISO_ZONED_DATE_TIME format", inputDate);
	}

	return convertedDate;
}
 
@Test
void recordVariableCreate() {
    VariableInstanceEntity variable = new VariableInstanceEntityImpl();
    Date createTime = Date.from(Instant.now().minusSeconds(5));
    compositeHistoryManager.recordVariableCreate(variable, createTime);

    verify(historyManager1).recordVariableCreate(same(variable), eq(createTime));
    verify(historyManager2).recordVariableCreate(same(variable), eq(createTime));
}
 
源代码6 项目: openemm   文件: Column.java
private Date calc (Expression expression, Date valueParameter) {
	if ((expression != null) && (valueParameter != null) && (! isnull)) {
		Instant	i = valueParameter.toInstant ();
		double	day = 24 * 60 * 60;
		double	epoch = i.getEpochSecond () / day;
		double	result = calc (expression, epoch);
		
		if (result != epoch) {
			i = Instant.ofEpochSecond ((long) (result * day));
			valueParameter = Date.from (i);
		}
	}
	return valueParameter;
}
 
源代码7 项目: ats-framework   文件: BlobInfo.java
BlobInfo( String containerName, String blobName, BlobProperties properties ) {

        this(containerName, blobName, properties.getContentMd5(),
             properties.getBlobSize(), properties.getETag(), properties.getContentType(),
             toAtsBlobType(properties.getBlobType()),
             Date.from(properties.getLastModified().toInstant()),
             Date.from(properties.getCreationTime().toInstant()), properties.getMetadata(),
             toAtsAccessTier(properties.getAccessTier()));
    }
 
源代码8 项目: kaif   文件: V1UserResource.java
@ApiOperation(value = "[public] Get basic information of the user",
    notes = "Get other user's basic information.")
@RequiredScope(ClientAppScope.PUBLIC)
@RequestMapping(value = "/{username}/basic", method = RequestMethod.GET)
public V1UserBasicDto basicByUsername(ClientAppUserAccessToken accessToken,
    @PathVariable("username") String username) {
  Account account = accountService.loadAccount(username);
  return new V1UserBasicDto(account.getUsername(),
      account.getDescription(),
      Date.from(account.getCreateTime()));
}
 
@Test
public void testConvert() {
    Instant now = Instant.now();
    Date nowDate = Date.from(now);

    //init
    subscriptionEntity = new SubscriptionEntity();
   
    subscriptionEntity.setApi(SUBSCRIPTION_API);
    subscriptionEntity.setApplication(SUBSCRIPTION_APPLICATION);
    subscriptionEntity.setClientId(SUBSCRIPTION_CLIENT_ID);
    subscriptionEntity.setClosedAt(nowDate);
    subscriptionEntity.setCreatedAt(nowDate);
    subscriptionEntity.setEndingAt(nowDate);
    subscriptionEntity.setId(SUBSCRIPTION_ID);
    subscriptionEntity.setPausedAt(nowDate);
    subscriptionEntity.setPlan(SUBSCRIPTION_PLAN);
    subscriptionEntity.setProcessedAt(nowDate);
    subscriptionEntity.setProcessedBy(SUBSCRIPTION_PROCESSED_BY);
    subscriptionEntity.setReason(SUBSCRIPTION_REASON);
    subscriptionEntity.setRequest(SUBSCRIPTION_REQUEST);
    subscriptionEntity.setStartingAt(nowDate);
    subscriptionEntity.setStatus(SubscriptionStatus.ACCEPTED);
    subscriptionEntity.setSubscribedBy(SUBSCRIPTION_SUBSCRIBED_BY);
    subscriptionEntity.setUpdatedAt(nowDate);
    
    
    //Test
    Subscription subscription = subscriptionMapper.convert(subscriptionEntity);
    assertNotNull(subscription);
    
    assertEquals(SUBSCRIPTION_API, subscription.getApi());
    assertEquals(SUBSCRIPTION_APPLICATION, subscription.getApplication());
    assertEquals(now.toEpochMilli(), subscription.getCreatedAt().toInstant().toEpochMilli());
    assertEquals(now.toEpochMilli(), subscription.getEndAt().toInstant().toEpochMilli());
    assertEquals(SUBSCRIPTION_ID, subscription.getId());
    assertEquals(SUBSCRIPTION_PLAN, subscription.getPlan());
    assertEquals(now.toEpochMilli(), subscription.getProcessedAt().toInstant().toEpochMilli());
    assertEquals(SUBSCRIPTION_REQUEST, subscription.getRequest());
    assertEquals(now.toEpochMilli(), subscription.getStartAt().toInstant().toEpochMilli());
    assertEquals(StatusEnum.ACCEPTED, subscription.getStatus());
    
}
 
源代码10 项目: vertx-rabbitmq-client   文件: Utils.java
public static Date parseDate(String date) {
  if (date == null) return null;

  OffsetDateTime odt = OffsetDateTime.parse(date, dateTimeFormatter);
  return Date.from(odt.toInstant());
}
 
源代码11 项目: kaif   文件: HotArticleRssContentView.java
private Date buildFeedUpdateTime(List<Article> articles, Instant fallbackTime) {
  return Date.from(articles.stream()
      .collect(maxBy(comparing(Article::getCreateTime)))
      .map(Article::getCreateTime)
      .orElse(fallbackTime));
}
 
源代码12 项目: mini-platform   文件: DateTimeUtils.java
/**
 * 将LocalDateTime 转换成 Date
 */
public static Date localDateTimeToDate(LocalDateTime localDateTime) {
    ZoneId zoneId = ZoneId.systemDefault();
    ZonedDateTime zdt = localDateTime.atZone(zoneId);
    return Date.from(zdt.toInstant());
}
 
源代码13 项目: Open-Lowcode   文件: DateUtils.java
/**
 * @return the start of week (sunday in the US, monday in France) at 0am in the
 *         current timezone
 */
public static Date getStartOfThisWeek() {

	return Date.from(LocalDate.now().minusDays(LocalDate.now().getDayOfWeek().getValue()).atStartOfDay()
			.atZone(ZoneId.systemDefault()).toInstant());
}
 
@Override
public Date convert(Instant in, Context context) throws Exception {
    if (in == null) return null;
    return Date.from(in);
}
 
源代码15 项目: gremlin-ogm   文件: Primitives.java
public static Date toDate(Instant instant) {
  return Date.from(instant);
}
 
源代码16 项目: cf-java-client-sap   文件: RawCloudEntityTest.java
static Date fromZonedDateTime(ZonedDateTime dateTime) {
    return Date.from(dateTime.toInstant());
}
 
源代码17 项目: basic-tools   文件: Dates.java
/**
 * 昨天零点
 *
 * @return
 */
public static Date yesterday() {
    LocalDateTime startOfDay = LocalDate.now().minusDays(1).atStartOfDay();
    Date today = Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
    return new Date();
}
 
protected SamlAssertionWrapper createSamlAssertion(Idp idp, TrustedIdp trustedIdp, JsonMapObject claims, 
                                                 String subjectName,
                                                 Instant notBefore,
                                                 Instant expires) throws Exception {
    SamlCallbackHandler callbackHandler = new SamlCallbackHandler();
    String issuer = idp.getServiceDisplayName();
    if (issuer == null) {
        issuer = idp.getRealm();
    }
    if (issuer != null) {
        callbackHandler.setIssuer(issuer);
    }

    // Subject
    SubjectBean subjectBean =
        new SubjectBean(subjectName, SAML2Constants.NAMEID_FORMAT_UNSPECIFIED, SAML2Constants.CONF_BEARER);
    callbackHandler.setSubjectBean(subjectBean);

    // Conditions
    ConditionsBean conditionsBean = new ConditionsBean();
    conditionsBean.setNotAfter(new DateTime(Date.from(expires)));
    if (notBefore != null) {
        DateTime notBeforeDT = new DateTime(Date.from(notBefore));
        conditionsBean.setNotBefore(notBeforeDT);
    } else {
        conditionsBean.setNotBefore(new DateTime());
    }
    callbackHandler.setConditionsBean(conditionsBean);

    // Claims
    String claimsHandler = getProperty(trustedIdp, CLAIMS_HANDLER);
    if (claimsHandler != null) {
        ClaimsHandler claimsHandlerImpl = (ClaimsHandler)Loader.loadClass(claimsHandler).newInstance();
        AttributeStatementBean attrStatementBean = claimsHandlerImpl.handleClaims(claims);
        callbackHandler.setAttrBean(attrStatementBean);
    }

    SAMLCallback samlCallback = new SAMLCallback();
    SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);

    SamlAssertionWrapper assertion = new SamlAssertionWrapper(samlCallback);

    Crypto crypto = CertsUtils.getCryptoFromCertificate(idp.getCertificate());
    assertion.signAssertion(crypto.getDefaultX509Identifier(), idp.getCertificatePassword(),
                            crypto, false);

    return assertion;
}
 
源代码19 项目: daming   文件: ZonedClock.java
@Override
public Date now() {
    return Date.from(ZonedDateTime.now(zoneId).toInstant());
}
 
源代码20 项目: BlogManagePlatform   文件: DateUtil.java
/**
 * 格式化日期(yyyy-MM-dd HH:mm:ss.SSS格式)
 * @see frodez.constant.settings.DefTime#PRECISIVE_PATTERN
 * @author Frodez
 * @date 2019-02-17
 */
public static Date precisiveTime(String date) {
	return Date.from(LocalDateTime.parse(date, DefTime.PRECISIVE_FORMATTER).atOffset(DefTime.DEFAULT_OFFSET).toInstant());
}