本文整理汇总了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));
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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");
}
示例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.");
}
}
示例10: now
import java.util.Date; //导入方法依赖的package包/类
@Override
public Date now() {
return Date.from(instantNow());
}
示例11: determineTradeWindowStartDate
import java.util.Date; //导入方法依赖的package包/类
private Date determineTradeWindowStartDate(){
LocalDateTime today = LocalDateTime.now();
return Date.from(today.atZone(ZoneId.systemDefault()).toInstant());
}
示例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");
}
示例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);
}
}
示例14: toDate
import java.util.Date; //导入方法依赖的package包/类
public static Date toDate(final long _timestamp) {
return Date.from(Instant.ofEpochMilli(_timestamp));
}
示例15: toDate
import java.util.Date; //导入方法依赖的package包/类
public static Date toDate(ZonedDateTime zonedDateTime) {
return Date.from(zonedDateTime.toInstant());
}