Java Code Examples for java.util.Date#from()
The following examples show how to use
java.util.Date#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: PreSignInResource.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@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; }
Example 2
Source File: LocalDateTimePersistenceConverter.java From aprendendo-vraptor with Apache License 2.0 | 5 votes |
@Override public Date convertToDatabaseColumn(LocalDateTime localDateTime) { if(localDateTime != null) { Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant(); return Date.from(instant); } return null; }
Example 3
Source File: ValueMetaStringTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@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 ); }
Example 4
Source File: DateFormatterUtil.java From sakai with Educational Community License v2.0 | 5 votes |
/** * 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; }
Example 5
Source File: V1UserResource.java From kaif with Apache License 2.0 | 5 votes |
@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())); }
Example 6
Source File: CompositeCmmnHistoryManagerTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@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)); }
Example 7
Source File: Column.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
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; }
Example 8
Source File: BlobInfo.java From ats-framework with Apache License 2.0 | 5 votes |
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())); }
Example 9
Source File: ZonedClock.java From daming with Apache License 2.0 | 4 votes |
@Override public Date now() { return Date.from(ZonedDateTime.now(zoneId).toInstant()); }
Example 10
Source File: AbstractTrustedIdpOAuth2ProtocolHandler.java From cxf-fediz with Apache License 2.0 | 4 votes |
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; }
Example 11
Source File: Dates.java From basic-tools with MIT License | 4 votes |
/** * 昨天零点 * * @return */ public static Date yesterday() { LocalDateTime startOfDay = LocalDate.now().minusDays(1).atStartOfDay(); Date today = Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant()); return new Date(); }
Example 12
Source File: RawCloudEntityTest.java From cf-java-client-sap with Apache License 2.0 | 4 votes |
static Date fromZonedDateTime(ZonedDateTime dateTime) { return Date.from(dateTime.toInstant()); }
Example 13
Source File: Primitives.java From gremlin-ogm with Apache License 2.0 | 4 votes |
public static Date toDate(Instant instant) { return Date.from(instant); }
Example 14
Source File: JavaInstantTojuDateConverter.java From SimpleFlatMapper with MIT License | 4 votes |
@Override public Date convert(Instant in, Context context) throws Exception { if (in == null) return null; return Date.from(in); }
Example 15
Source File: DateUtils.java From Open-Lowcode with Eclipse Public License 2.0 | 4 votes |
/** * @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()); }
Example 16
Source File: DateTimeUtils.java From mini-platform with MIT License | 4 votes |
/** * 将LocalDateTime 转换成 Date */ public static Date localDateTimeToDate(LocalDateTime localDateTime) { ZoneId zoneId = ZoneId.systemDefault(); ZonedDateTime zdt = localDateTime.atZone(zoneId); return Date.from(zdt.toInstant()); }
Example 17
Source File: HotArticleRssContentView.java From kaif with Apache License 2.0 | 4 votes |
private Date buildFeedUpdateTime(List<Article> articles, Instant fallbackTime) { return Date.from(articles.stream() .collect(maxBy(comparing(Article::getCreateTime))) .map(Article::getCreateTime) .orElse(fallbackTime)); }
Example 18
Source File: Utils.java From vertx-rabbitmq-client with Apache License 2.0 | 4 votes |
public static Date parseDate(String date) { if (date == null) return null; OffsetDateTime odt = OffsetDateTime.parse(date, dateTimeFormatter); return Date.from(odt.toInstant()); }
Example 19
Source File: SubscriptionMapperTest.java From gravitee-management-rest-api with Apache License 2.0 | 4 votes |
@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()); }
Example 20
Source File: DateUtil.java From BlogManagePlatform with Apache License 2.0 | 2 votes |
/** * 格式化日期(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()); }