本文整理了Java中java.time.LocalTime.atDate()
方法的一些代码示例,展示了LocalTime.atDate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalTime.atDate()
方法的具体详情如下:
包路径:java.time.LocalTime
类名称:LocalTime
方法名:atDate
[英]Combines this time with a date to create a LocalDateTime.
This returns a LocalDateTime formed from this time at the specified date. All possible combinations of date and time are valid.
[中]将此时间与日期组合以创建LocalDateTime。
这将返回从此时间在指定日期形成的LocalDateTime。所有可能的日期和时间组合均有效。
代码示例来源:origin: hibernate/hibernate-orm
final ZonedDateTime zonedDateTime = value.atDate( LocalDate.of( 1970, 1, 1 ) ).atZone( ZoneId.systemDefault() );
代码示例来源:origin: org.mongodb/mongo-java-driver
/**
* {@inheritDoc}
* <p>Converts the {@code LocalTime} to {@link ZoneOffset#UTC} at EpochDay via {@link LocalTime#atDate(LocalDate)} and
* {@link java.time.LocalDateTime#toInstant(ZoneOffset)}.</p>
*/
@Override
public void encode(final BsonWriter writer, final LocalTime value, final EncoderContext encoderContext) {
writer.writeDateTime(value.atDate(LocalDate.ofEpochDay(0L)).toInstant(ZoneOffset.UTC).toEpochMilli());
}
代码示例来源:origin: apache/nifi
final DateTimeFormatter dtFormatter = getDateTimeFormatter(valueFormat);
LocalTime parsedTime = LocalTime.parse(parameterValue, dtFormatter);
LocalDateTime localDateTime = parsedTime.atDate(LocalDate.ofEpochDay(0));
Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
time = new Time(instant.toEpochMilli());
代码示例来源:origin: prestodb/presto
@Test
public void testLocallyUnrepresentableTimeLiterals()
{
LocalDateTime localTimeThatDidNotExist = LocalDateTime.of(2017, 4, 2, 2, 10);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotExist).isEmpty(), "This test assumes certain JVM time zone");
// This tests that both Presto runner and H2 can return TIMESTAMP value that never happened in JVM's zone (e.g. is not representable using java.sql.Timestamp)
@Language("SQL") String sql = DateTimeFormatter.ofPattern("'SELECT TIMESTAMP '''uuuu-MM-dd HH:mm:ss''").format(localTimeThatDidNotExist);
assertEquals(computeScalar(sql), localTimeThatDidNotExist); // this tests Presto and the QueryRunner
assertQuery(sql); // this tests H2QueryRunner
LocalDate localDateThatDidNotHaveMidnight = LocalDate.of(1970, 1, 1);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(localDateThatDidNotHaveMidnight.atStartOfDay()).isEmpty(), "This test assumes certain JVM time zone");
// This tests that both Presto runner and H2 can return DATE value for a day which midnight never happened in JVM's zone (e.g. is not exactly representable using java.sql.Date)
sql = DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(localDateThatDidNotHaveMidnight);
assertEquals(computeScalar(sql), localDateThatDidNotHaveMidnight); // this tests Presto and the QueryRunner
assertQuery(sql); // this tests H2QueryRunner
LocalTime localTimeThatDidNotOccurOn19700101 = LocalTime.of(0, 10);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotOccurOn19700101.atDate(LocalDate.ofEpochDay(0))).isEmpty(), "This test assumes certain JVM time zone");
checkState(!Objects.equals(java.sql.Time.valueOf(localTimeThatDidNotOccurOn19700101).toLocalTime(), localTimeThatDidNotOccurOn19700101), "This test assumes certain JVM time zone");
sql = DateTimeFormatter.ofPattern("'SELECT TIME '''HH:mm:ss''").format(localTimeThatDidNotOccurOn19700101);
assertEquals(computeScalar(sql), localTimeThatDidNotOccurOn19700101); // this tests Presto and the QueryRunner
assertQuery(sql); // this tests H2QueryRunner
}
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
return GregorianCalendar.from(lt.atDate(LocalDate.ofEpochDay(0)).atZone(ZoneId.systemDefault()));
} catch (final DateTimeParseException e) {
return GregorianCalendar.from(lt.atDate(LocalDate.ofEpochDay(0)).atZone(ZoneId.systemDefault()));
} catch (final DateTimeParseException e) {
代码示例来源:origin: stackoverflow.com
LocalTime lt = ...;
Instant instant = lt.atDate(LocalDate.of(A_YEAR, A_MONTH, A_DAY)).
atZone(ZoneId.systemDefault()).toInstant();
Date time = Date.from(instant);
代码示例来源:origin: org.simpleflatmapper/sfm-converter
@Override
public Date convert(LocalTime in, Context context) throws Exception {
if (in == null) return null;
return Date.from(in.atDate(LocalDate.now()).atZone(dateTimeZone).toInstant());
}
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
@Override
public Date convert(LocalTime in, Context context) throws Exception {
if (in == null) return null;
return Date.from(in.atDate(LocalDate.now()).atZone(dateTimeZone).toInstant());
}
}
代码示例来源:origin: quickfix-j/quickfixj
/**
* @param localTime
* @return a java.util.Date with time part filled from LocalTime (truncated to milliseconds).
*/
public static Date getDate(LocalTime localTime) {
if (localTime != null) {
return Date.from(localTime.atDate(LocalDate.ofEpochDay(0)).atZone(ZoneOffset.UTC).toInstant());
}
return null;
}
代码示例来源:origin: net.s-jr.utils.converterutils/java8-converter-utils
@Contract("null -> null; !null -> !null")
public static @Nullable Date localTimeToUtilDate(final @Nullable LocalTime d) {
if (d == null) {
return null;
}
return Date.from(d.atDate(LocalDate.now()).atZone(ZoneId.systemDefault()).toInstant());
}
}
代码示例来源:origin: com.github.almex/raildelays-api
/**
* Translate a {@link TimeDelay} into a {@link LocalDateTime}.
*
* @param date the date to combien with, not null
* @return a non-null {@link LocalDateTime} which is a combination of {@code expectedTime}
* plus its {@code delay} and the {@code date}.
*/
public LocalDateTime atDate(LocalDate date) {
return getEffectiveTime().atDate(date);
}
代码示例来源:origin: io.atlasmap/atlas-core
@AtlasConversionInfo(sourceType = FieldType.TIME, targetType = FieldType.DATE_TIME)
public LocalDateTime toLocalDateTime(LocalTime value) {
return value != null ? value.atDate(LocalDate.now()) : null;
}
代码示例来源:origin: io.atlasmap/atlas-core
@AtlasConversionInfo(sourceType = FieldType.TIME, targetType = FieldType.DATE_TIME_TZ)
public ZonedDateTime toZonedDateTime(LocalTime value) {
return value != null ? value.atDate(LocalDate.now()).atZone(ZoneId.systemDefault()) : null;
}
代码示例来源:origin: io.atlasmap/atlas-core
@AtlasConversionInfo(sourceType = FieldType.TIME, targetType = FieldType.DATE_TIME)
public java.sql.Timestamp toSqlTimestamp(LocalTime value) {
return value != null ? java.sql.Timestamp.valueOf(value.atDate(LocalDate.now())) : null;
}
代码示例来源:origin: eclipse/hawkbit
private static Date durationToDate(final Duration duration) {
if (duration.compareTo(MAXIMUM_DURATION) > 0) {
throw new IllegalArgumentException("The duaration has to be smaller than 23:59:59.");
}
final LocalTime lt = LocalTime.ofNanoOfDay(duration.toNanos());
return Date.from(lt.atDate(LocalDate.now(ZONEID_UTC)).atZone(ZONEID_UTC).toInstant());
}
代码示例来源:origin: io.atlasmap/atlas-core
@AtlasConversionInfo(sourceType = FieldType.TIME, targetType = FieldType.DATE_TIME_TZ)
public GregorianCalendar toGregorianCalendar(LocalTime value) {
return value != null ? GregorianCalendar.from(value.atDate(LocalDate.now()).atZone(ZoneId.systemDefault())) : null;
}
代码示例来源:origin: org.apache.drill.exec/drill-java-exec
public void eval() {
byte[] buf = new byte[in.end - in.start];
in.buffer.getBytes(in.start, buf, 0, in.end - in.start);
String input = new String(buf, com.google.common.base.Charsets.UTF_8);
java.time.format.DateTimeFormatter f = org.apache.drill.exec.expr.fn.impl.DateUtility.getTimeFormatter();
out.value = (int) (java.time.LocalTime.parse(input, f).atDate(java.time.LocalDate.ofEpochDay(0)).toInstant(java.time.ZoneOffset.UTC).toEpochMilli());
}
}
代码示例来源:origin: org.apache.drill.exec/drill-java-exec
public void eval() {
if(in.end == in.start) {
out.isSet = 0;
return;
}
out.isSet = 1;
byte[] buf = new byte[in.end - in.start];
in.buffer.getBytes(in.start, buf, 0, in.end - in.start);
String input = new String(buf, com.google.common.base.Charsets.UTF_8);
java.time.format.DateTimeFormatter f = org.apache.drill.exec.expr.fn.impl.DateUtility.getTimeFormatter();
out.value = (int) (java.time.LocalTime.parse(input, f).atDate(java.time.LocalDate.ofEpochDay(0)).toInstant(java.time.ZoneOffset.UTC).toEpochMilli());
}
}
代码示例来源:origin: org.apache.drill.exec/drill-java-exec
public void eval() {
if(in.isSet == 0 || in.end == in.start) {
out.isSet = 0;
return;
}
out.isSet = 1;
byte[] buf = new byte[in.end - in.start];
in.buffer.getBytes(in.start, buf, 0, in.end - in.start);
String input = new String(buf, com.google.common.base.Charsets.UTF_8);
java.time.format.DateTimeFormatter f = org.apache.drill.exec.expr.fn.impl.DateUtility.getTimeFormatter();
out.value = (int) (java.time.LocalTime.parse(input, f).atDate(java.time.LocalDate.ofEpochDay(0)).toInstant(java.time.ZoneOffset.UTC).toEpochMilli());
}
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
@Test
public void testJavaLocalTime() throws Exception {
java.time.LocalTime value = java.time.LocalTime.now();
java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles");
newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.LocalTime>(value), java.time.LocalTime.class, new JavaZoneIdProperty(zoneId));
newFieldMapperAndMapToPS(NullGetter.<Object, java.time.LocalTime>getter(), java.time.LocalTime.class);
verify(ps).setTime(1, new Time(value.atDate(LocalDate.now()).atZone(zoneId).toInstant().toEpochMilli()));
verify(ps).setNull(2, Types.TIME);
}
内容来源于网络,如有侵权,请联系作者删除!