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


Java Date.from方法代碼示例

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


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

示例1: onFindAvailableRoomsButtonClicked

import java.util.Date; //導入方法依賴的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

示例2: getEventFromJson

import java.util.Date; //導入方法依賴的package包/類
/**
 * Parse an object node in order to create an {@link Event} object
 *
 * @param objectNode object node to convert to {@link Event}
 * @return {@link Event} converted format
 * @see TwitterMock#SOURCE
 */
@Override
public Event getEventFromJson(ObjectNode objectNode) {
    Date startDate = Date.from(Instant.ofEpochMilli(objectNode.findValue("timestamp_ms").asLong()));
    Date endDate = Date.from(Instant.now());
    JsonNode jsonNode = objectNode.findValue("place");
    JsonNode jsonCoordinates = jsonNode.findValue("coordinates");
    String description = objectNode.findValue("text").toString();
    LatLong latLong = jsonToLatLong(jsonCoordinates);
    try {
        return new Event(latLong, startDate, endDate, description, SOURCE);
    } catch (IllegalArgumentException | NullPointerException err) {
        LOGGER.error(err.getMessage());
        return null;
    }
}
 
開發者ID:IKB4Stream,項目名稱:IKB4Stream,代碼行數:23,代碼來源:TwitterMock.java

示例3: of

import java.util.Date; //導入方法依賴的package包/類
public static User of(String email, String name) {
	User user = new User();
	user.email = email;
	user.name = name;
	user.nickname = name;
	user.password = email;

	ZonedDateTime utc = ZonedDateTime.now(ZoneOffset.UTC);
	user.joinedAt = Date.from(utc.toInstant());

	return user;
}
 
開發者ID:spring-sprout,項目名稱:osoon,代碼行數:13,代碼來源:User.java

示例4: getEndCookieDate

import java.util.Date; //導入方法依賴的package包/類
public static Date getEndCookieDate(int days) {
    Date date = new Date();
    LocalDateTime localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
    localDate = localDate.plusDays(days);
    Date cookieEndDate = Date.from(localDate.atZone(ZoneId.systemDefault()).toInstant());
    return cookieEndDate;
}
 
開發者ID:xSzymo,項目名稱:Spring-web-shop-project,代碼行數:8,代碼來源:CookiesDAO.java

示例5: localDateToDate

import java.util.Date; //導入方法依賴的package包/類
/**
 * Cette méthode transforme un objet LocalDate (Java 8) en un objet Date.
 * L'objet LocalDate ne possédant pas d'heure, on lui donne minuit et la zone horaire du système.
 *
 * @param localDate l'objet LocalDate à transformer en Date
 * @return l'objet Date correspondant à l'objet LocalDate
 */
public static Date localDateToDate(LocalDate localDate) {
  if (localDate != null) {
    return Date.from(Instant.from(localDate.atStartOfDay(ZoneId.systemDefault())));
  } else {
    return null;
  }
}
 
開發者ID:elgoupil,項目名稱:GoupilBot,代碼行數:15,代碼來源:DateTimeLib.java

示例6: getDaysFromNow

import java.util.Date; //導入方法依賴的package包/類
/**
 * Adds the given number of days to today and returns the new date
 * 
 * @param days
 * @return
 */
public static Date getDaysFromNow(int days) {
	LocalDate localDate = LocalDate.now().plus(days, ChronoUnit.DAYS);
	Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
	return date;

}
 
開發者ID:michaelnetter,項目名稱:dracoon-dropzone,代碼行數:13,代碼來源:Util.java

示例7: convertToPresentation

import java.util.Date; //導入方法依賴的package包/類
@Override
public Date convertToPresentation(LocalDate value, Class<? extends Date> targetType, Locale locale)
		throws com.vaadin.data.util.converter.Converter.ConversionException {
	if (value != null) {
		return Date.from(value.atStartOfDay(getTimeZone()).toInstant());
	}
	return null;
}
 
開發者ID:holon-platform,項目名稱:holon-vaadin7,代碼行數:9,代碼來源:DateToLocalDateConverter.java

示例8: choiceStateWithAllPrimitiveConditions

import java.util.Date; //導入方法依賴的package包/類
@Test
public void choiceStateWithAllPrimitiveConditions() {
    final Date date = Date.from(ZonedDateTime.parse("2016-03-14T01:59:00.000Z").toInstant());
    final StateMachine stateMachine = stateMachine()
            .startAt("InitialState")
            .state("InitialState", choiceState()
                    .defaultStateName("DefaultState")
                    .choice(choice().transition(next("NextState"))
                                    .condition(and(
                                            eq("$.string", "value"),
                                            gt("$.string", "value"),
                                            gte("$.string", "value"),
                                            lt("$.string", "value"),
                                            lte("$.string", "value"),
                                            eq("$.integral", 42),
                                            gt("$.integral", 42),
                                            gte("$.integral", 42),
                                            lt("$.integral", 42),
                                            lte("$.integral", 42),
                                            eq("$.double", 9000.1),
                                            gt("$.double", 9000.1),
                                            gte("$.double", 9000.1),
                                            lt("$.double", 9000.1),
                                            lte("$.double", 9000.1),
                                            eq("$.timestamp", date),
                                            gt("$.timestamp", date),
                                            gte("$.timestamp", date),
                                            lt("$.timestamp", date),
                                            lte("$.timestamp", date),
                                            eq("$.boolean", true),
                                            eq("$.boolean", false)
                                                  ))))
            .state("NextState", succeedState())
            .state("DefaultState", succeedState())
            .build();

    assertStateMachine(stateMachine, "ChoiceStateWithAllPrimitiveCondition.json");
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:39,代碼來源:StepFunctionBuilderTest.java

示例9: setupFS

import java.util.Date; //導入方法依賴的package包/類
private void setupFS() throws IOException {
    log.config("Setting up filesystem...");

    Collection<File> directories = new ArrayList<File>();

    File reportsfolder = new File("ng-reports");

    directories.add(bridge.getNGFolder());
    directories.add(new File(bridge.getNGFolder(), "config"));
    directories.add(new File(bridge.getNGFolder(), "data"));
    directories.add(new File(bridge.getNGFolder(), "commands"));
    directories.add(new File(bridge.getNGFolder(), "scripts"));
    directories.add(reportsfolder);

    for (File f : directories) {
        if (f == null) continue;
        if (!f.exists()) {
            f.mkdir();
        } else {
            if (!f.isDirectory()) {
                if (f.delete()) {
                    f.mkdir();
                } else {
                    reportError(new IOException("Cannot fix " + f.getName() + "."));
                }
            }
        }
    }

    if (!System.getProperty("nekoooguilds.dontcleanreports", "false").equalsIgnoreCase("true")) {
        log.config("Cleaning up old reports...");
        LocalDate today = LocalDate.now();
        LocalDate eailer = today.minusDays(14);

        Date threshold = Date.from(eailer.atStartOfDay(ZoneId.systemDefault()).toInstant());
        AgeFileFilter filter = new AgeFileFilter(threshold);

        File[] remove = FileFilterUtils.filter(filter, reportsfolder);

        for (File file : remove) {
            if (file.delete()) log.config("Deleted " + file.getName());
        }
    } else {
        log.info("Report cleanup disabled with JVM/PropertyLoader option.");
    }
}
 
開發者ID:NekoooGuilds,項目名稱:NekoooGuilds,代碼行數:47,代碼來源:NekoooGuilds.java

示例10: now

import java.util.Date; //導入方法依賴的package包/類
@Override
public Date now() {
    return Date.from(instantNow());
}
 
開發者ID:membaza,項目名稱:users-service,代碼行數:5,代碼來源:DateServiceImpl.java

示例11: determineTradeWindowStartDate

import java.util.Date; //導入方法依賴的package包/類
private Date determineTradeWindowStartDate(){
 LocalDateTime today = LocalDateTime.now();
 return Date.from(today.atZone(ZoneId.systemDefault()).toInstant());
 
}
 
開發者ID:aslakknutsen,項目名稱:trade-insights,代碼行數:6,代碼來源:TradeRecommendationsEngine.java

示例12: doGet

import java.util.Date; //導入方法依賴的package包/類
@RequestMapping(value = "get", produces = "application/json", method = RequestMethod.GET)
public OrderObject doGet(){
     return new OrderObject(new HashMap<Long, Long>(), Date.from(Instant.now()), "ceva");
}
 
開發者ID:stoiandan,項目名稱:OnlineShop,代碼行數:5,代碼來源:OrderController.java

示例13: createIdToken

import java.util.Date; //導入方法依賴的package包/類
@Override
public JWT createIdToken(IdTokenRequest idTokenRequest) {
	Instant now = Instant.now();
	Subject subject = idTokenRequest.getSubject();
	OIDCClientInformation client = idTokenRequest.getClient();
	ClientID clientId = client.getID();
	JWSAlgorithm algorithm = client.getOIDCMetadata().getIDTokenJWSAlg();
	UserInfo userInfo = this.claimSource.load(subject, resolveClaims(idTokenRequest));
	List<Audience> audience = Audience.create(clientId.getValue());
	Date expirationTime = Date.from(now.plus(this.idTokenLifetime));
	Date issueTime = Date.from(now);

	IDTokenClaimsSet claimsSet = new IDTokenClaimsSet(this.issuer, userInfo.getSubject(), audience, expirationTime,
			issueTime);
	claimsSet.setAuthenticationTime(Date.from(idTokenRequest.getAuthenticationTime()));
	claimsSet.setNonce(idTokenRequest.getNonce());
	claimsSet.setACR(idTokenRequest.getAcr());
	claimsSet.setAMR(Collections.singletonList(idTokenRequest.getAmr()));
	claimsSet.setAuthorizedParty(new AuthorizedParty(clientId.getValue()));
	claimsSet.putAll(userInfo);

	if (this.frontChannelLogoutEnabled) {
		SessionID sessionId = idTokenRequest.getSessionId();
		claimsSet.setSessionID(sessionId);
	}

	AccessToken accessToken = idTokenRequest.getAccessToken();

	if (accessToken != null) {
		AccessTokenHash accessTokenHash = AccessTokenHash.compute(accessToken, algorithm);
		claimsSet.setAccessTokenHash(accessTokenHash);
	}

	AuthorizationCode code = idTokenRequest.getCode();

	if (code != null) {
		CodeHash codeHash = CodeHash.compute(code, algorithm);
		claimsSet.setCodeHash(codeHash);
	}

	try {
		JWTAssertionDetails details = JWTAssertionDetails.parse(claimsSet.toJWTClaimsSet());

		if (JWSAlgorithm.Family.HMAC_SHA.contains(algorithm)) {
			Secret secret = client.getSecret();

			return JWTAssertionFactory.create(details, algorithm, secret);
		}
		else if (JWSAlgorithm.Family.RSA.contains(algorithm)) {
			RSAKey rsaKey = (RSAKey) resolveJwk(algorithm);

			return JWTAssertionFactory.create(details, algorithm, rsaKey.toRSAPrivateKey(), rsaKey.getKeyID(),
					jcaProvider);
		}
		else if (JWSAlgorithm.Family.EC.contains(algorithm)) {
			ECKey ecKey = (ECKey) resolveJwk(algorithm);

			return JWTAssertionFactory.create(details, algorithm, ecKey.toECPrivateKey(), ecKey.getKeyID(),
					jcaProvider);
		}

		throw new KeyException("Unsupported algorithm: " + algorithm);
	}
	catch (ParseException | JOSEException e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:vpavic,項目名稱:simple-openid-provider,代碼行數:68,代碼來源:DefaultTokenService.java

示例14: toDate

import java.util.Date; //導入方法依賴的package包/類
public static Date toDate(final long _timestamp) {
    return Date.from(Instant.ofEpochMilli(_timestamp));
}
 
開發者ID:jonfryd,項目名稱:tifoon,代碼行數:4,代碼來源:TimeHelper.java

示例15: toDate

import java.util.Date; //導入方法依賴的package包/類
public static Date toDate(ZonedDateTime zonedDateTime) {
    return Date.from(zonedDateTime.toInstant());
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:4,代碼來源:DateUtil.java


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