本文整理了Java中java.util.Date.from()
方法的一些代码示例,展示了Date.from()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Date.from()
方法的具体详情如下:
包路径:java.util.Date
类名称:Date
方法名:from
暂无
代码示例来源:origin: lets-blade/blade
public Date format(String date, String pattern) {
DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern, Locale.US);
LocalDateTime formatted = LocalDateTime.parse(date, fmt);
Instant instant = formatted.atZone(ZoneId.systemDefault()).toInstant();
return Date.from(instant);
}
代码示例来源:origin: lets-blade/blade
public Date format(String date, String pattern) {
DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern, Locale.US);
LocalDateTime formatted = LocalDateTime.parse(date, fmt);
Instant instant = formatted.atZone(ZoneId.systemDefault()).toInstant();
return Date.from(instant);
}
代码示例来源:origin: oblac/jodd
/**
* Converts local date to Date.
*/
public static Date toDate(final LocalDate localDate) {
return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
/**
代码示例来源:origin: oblac/jodd
/**
* Converts local date time to Date.
*/
public static Date toDate(final LocalDateTime localDateTime) {
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}
代码示例来源:origin: lets-blade/blade
public static Date toDateTime(String time, String pattern) {
LocalDateTime formatted = LocalDateTime.parse(time, DateTimeFormatter.ofPattern(pattern));
return Date.from(formatted.atZone(ZoneId.systemDefault()).toInstant());
}
代码示例来源:origin: lets-blade/blade
public static Date toDateTime(String time, String pattern) {
LocalDateTime formatted = LocalDateTime.parse(time, DateTimeFormatter.ofPattern(pattern));
return Date.from(formatted.atZone(ZoneId.systemDefault()).toInstant());
}
代码示例来源:origin: spring-projects/spring-data-jpa
@Override
public void setLastModifiedDate(LocalDateTime lastModifiedDate) {
this.lastModifiedDate = Date.from(lastModifiedDate.atZone(ZoneId.systemDefault()).toInstant());
}
}
代码示例来源:origin: MorphiaOrg/morphia
@Override
public Object encode(final Object value, final MappedField optionalExtraInfo) {
if (value == null) {
return null;
}
return Date.from(((LocalDateTime) value).atZone(systemDefault()).toInstant());
}
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public void serialize(ZonedDateTime zonedDateTime,
JsonGenerator jsonGenerator,
SerializerProvider serializerProvider) throws IOException {
final Instant instant = zonedDateTime.withZoneSameInstant(ZoneOffset.UTC).toInstant();
final Date date = Date.from(instant);
jsonGenerator.writeObject(date);
}
}
代码示例来源:origin: spring-projects/spring-data-jpa
@Override
public void setCreatedDate(LocalDateTime createdDate) {
this.createdDate = Date.from(createdDate.atZone(ZoneId.systemDefault()).toInstant());
}
代码示例来源:origin: MorphiaOrg/morphia
@Override
public Object encode(final Object value, final MappedField optionalExtraInfo) {
if (value == null) {
return null;
}
LocalDate date = (LocalDate) value;
return Date.from(date.atStartOfDay()
.atZone(systemDefault())
.toInstant());
}
}
代码示例来源:origin: SonarSource/sonarqube
/**
* Return a date at the start of day.
*
* @param s string in format {@link #DATE_FORMAT}
* @throws SonarException when string cannot be parsed
*/
public static Date parseDate(String s) {
return Date.from(parseLocalDate(s).atStartOfDay(ZoneId.systemDefault()).toInstant());
}
代码示例来源:origin: prestodb/presto
public String getBearerToken(String subject)
{
checkState(jwtSigner.isPresent(), "not configured");
JwtBuilder jwt = Jwts.builder()
.setSubject(subject)
.setExpiration(Date.from(ZonedDateTime.now().plusMinutes(5).toInstant()));
jwtSigner.get().accept(jwt);
jwtKeyId.ifPresent(keyId -> jwt.setHeaderParam(KEY_ID, keyId));
jwtIssuer.ifPresent(jwt::setIssuer);
jwtAudience.ifPresent(jwt::setAudience);
return jwt.compact();
}
代码示例来源:origin: yu199195/hmily
/**
* Gets date yyyy.
*
* @return the date yyyy
*/
public static Date getDateYYYY() {
LocalDateTime localDateTime = parseLocalDateTime(getCurrentDateTime());
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDateTime.atZone(zone).toInstant();
return Date.from(instant);
}
代码示例来源:origin: yu199195/Raincat
public static Date getDateYYYY() throws ParseException{
LocalDateTime localDateTime = parseLocalDateTime(getCurrentDateTime());
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDateTime.atZone(zone).toInstant();
return Date.from(instant);
}
代码示例来源:origin: SonarSource/sonarqube
/**
* Warning: may rely on default timezone!
*
* @return the datetime, {@code null} if stringDate is null
* @throws IllegalArgumentException if stringDate is not a correctly formed date or datetime
* @since 6.1
*/
@CheckForNull
public static Date parseDateOrDateTime(@Nullable String stringDate) {
if (stringDate == null) {
return null;
}
OffsetDateTime odt = parseOffsetDateTimeQuietly(stringDate);
if (odt != null) {
return Date.from(odt.toInstant());
}
LocalDate ld = parseLocalDateQuietly(stringDate);
checkArgument(ld != null, "Date '%s' cannot be parsed as either a date or date+time", stringDate);
return Date.from(ld.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
代码示例来源:origin: yu199195/myth
/**
* Gets date yyyy.
*
* @return the date yyyy
*/
public static Date getDateYYYY() {
LocalDateTime localDateTime = parseLocalDateTime(getCurrentDateTime());
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDateTime.atZone(zone).toInstant();
return Date.from(instant);
}
代码示例来源:origin: knowm/XChange
private static void raw(Exchange bfx) throws IOException {
/*
BitfinexTradeServiceRaw tradeService = (BitfinexTradeServiceRaw) bfx.getTradeService();
LimitOrder limitOrder = new LimitOrder.Builder(OrderType.BID, CurrencyPair.BTC_USD).limitPrice(new BigDecimal("481.69"))
.originalAmount(new BigDecimal("0.001")).build();
tradeService.placeBitfinexLimitOrder(limitOrder, BitfinexOrderType.LIMIT);
*/
BitfinexTradeServiceRaw tradeService = (BitfinexTradeServiceRaw) bfx.getTradeService();
Date tenDaysAgo =
Date.from(LocalDate.now().minusDays(10).atStartOfDay(ZoneId.systemDefault()).toInstant());
BitfinexFundingTradeResponse[] fundingTradeResponses =
tradeService.getBitfinexFundingHistory("USD", tenDaysAgo, 2000);
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
@SuppressWarnings("unchecked")
public <X> X unwrap(LocalDate value, Class<X> type, WrapperOptions options) {
if ( value == null ) {
return null;
}
if ( LocalDate.class.isAssignableFrom( type ) ) {
return (X) value;
}
if ( java.sql.Date.class.isAssignableFrom( type ) ) {
return (X) java.sql.Date.valueOf( value );
}
final LocalDateTime localDateTime = value.atStartOfDay();
if ( Timestamp.class.isAssignableFrom( type ) ) {
return (X) Timestamp.valueOf( localDateTime );
}
final ZonedDateTime zonedDateTime = localDateTime.atZone( ZoneId.systemDefault() );
if ( Calendar.class.isAssignableFrom( type ) ) {
return (X) GregorianCalendar.from( zonedDateTime );
}
final Instant instant = zonedDateTime.toInstant();
if ( Date.class.equals( type ) ) {
return (X) Date.from( instant );
}
if ( Long.class.isAssignableFrom( type ) ) {
return (X) Long.valueOf( instant.toEpochMilli() );
}
throw unknownUnwrap( type );
}
代码示例来源:origin: hibernate/hibernate-orm
Instant instant = value.atZone( ZoneId.systemDefault() ).toInstant();
return (X) java.sql.Timestamp.from( instant );
Instant instant = value.atZone( ZoneId.systemDefault() ).toInstant();
return (X) java.sql.Date.from( instant );
Instant instant = value.atZone( ZoneId.systemDefault() ).toInstant();
return (X) java.sql.Time.from( instant );
Instant instant = value.atZone( ZoneId.systemDefault() ).toInstant();
return (X) java.util.Date.from( instant );
内容来源于网络,如有侵权,请联系作者删除!