java.time.LocalDateTime.toLocalTime()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中java.time.LocalDateTime.toLocalTime()方法的一些代码示例,展示了LocalDateTime.toLocalTime()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.toLocalTime()方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:toLocalTime

LocalDateTime.toLocalTime介绍

[英]Gets the LocalTime part of this date-time.

This returns a LocalTime with the same hour, minute, second and nanosecond as this date-time.
[中]获取此日期时间的LocalTime部分。
这将返回与此日期时间相同的小时、分钟、秒和纳秒的本地时间。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
  public LocalTime convert(LocalDateTime source) {
    return source.toLocalTime();
  }
}

代码示例来源:origin: org.springframework/spring-context

@Override
  public LocalTime convert(LocalDateTime source) {
    return source.toLocalTime();
  }
}

代码示例来源:origin: neo4j/neo4j

@Override
LocalTime getLocalTimePart()
{
  return value.toLocalTime();
}

代码示例来源:origin: nutzam/nutz

@Override
public TemporalAccessor cast(Number src, Class<?> toType, String... args) {
  Date date = new Date(src.longValue());
  LocalDateTime dt = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
  if (toType == LocalDateTime.class)
    return dt;
  if (toType == LocalDate.class)
    return dt.toLocalDate();
  return dt.toLocalTime();
}

代码示例来源:origin: apache/drill

@Override
public LocalTime readLocalTime(){
 if (!isSet()) {
  return null;
 }
  return LocalDateTime.ofInstant(Instant.ofEpochMilli(this.holder.value), ZoneOffset.UTC).toLocalTime();
}

代码示例来源:origin: apache/drill

private Object readSingleObject() {
 if (!isSet()) {
  return null;
 }
  return LocalDateTime.ofInstant(Instant.ofEpochMilli(this.holder.value), ZoneOffset.UTC).toLocalTime();
}

代码示例来源:origin: prestodb/presto

/**
 * Constructs standard (non-legacy) TIMESTAMP value corresponding to argument
 */
public static SqlTimestamp sqlTimestampOf(LocalDateTime dateTime)
{
  return new SqlTimestamp(DAYS.toMillis(dateTime.toLocalDate().toEpochDay()) + NANOSECONDS.toMillis(dateTime.toLocalTime().toNanoOfDay()));
}

代码示例来源:origin: apache/drill

private Object readSingleObject() {
 if (!isSet()) {
  return null;
 }
  return LocalDateTime.ofInstant(Instant.ofEpochMilli(this.holder.value), ZoneOffset.UTC).toLocalTime();
}

代码示例来源:origin: apache/drill

@Override
public LocalTime readLocalTime(){
 if (!isSet()) {
  return null;
 }
  return LocalDateTime.ofInstant(Instant.ofEpochMilli(this.holder.value), ZoneOffset.UTC).toLocalTime();
}

代码示例来源:origin: prestodb/presto

private static Time toTime(int year, int month, int day, int hour, int minute, int second)
  {
    return Time.valueOf(LocalDateTime.of(year, month, day, hour, minute, second).toLocalTime());
  }
}

代码示例来源:origin: neo4j/neo4j

@Override
OffsetTime getTimePart( Supplier<ZoneId> defaultZone )
{
  ZoneOffset currentOffset = assertValidArgument( () -> ZonedDateTime.ofInstant( Instant.now(), defaultZone.get() ) ).getOffset();
  return OffsetTime.of(value.toLocalTime(), currentOffset);
}

代码示例来源:origin: prestodb/presto

public static Time castToTime(Object x, int targetSqlType)
    throws SQLException
{
  if (x instanceof Time) {
    return (Time) x;
  }
  if (x instanceof java.util.Date) {
    return new Time(((java.util.Date) x).getTime());
  }
  if (x instanceof LocalTime) {
    return Time.valueOf((LocalTime) x);
  }
  if (x instanceof LocalDateTime) {
    return Time.valueOf(((LocalDateTime) x).toLocalTime());
  }
  try {
    if (x instanceof String) {
      return Time.valueOf((String) x);
    }
  }
  catch (RuntimeException e) {
    throw invalidConversion(x, targetSqlType, e);
  }
  throw invalidConversion(x, targetSqlType);
}

代码示例来源:origin: jtablesaw/tablesaw

public static long pack(LocalDateTime dateTime) {
  if (dateTime == null) {
    return missingValueIndicator();
  }
  LocalDate date = dateTime.toLocalDate();
  LocalTime time = dateTime.toLocalTime();
  return (pack(date, time));
}

代码示例来源:origin: debezium/debezium

/**
 * Get the number of nanoseconds past epoch of the given {@link LocalDateTime}.
 *
 * @param timestamp the Java timestamp value
 * @return the epoch nanoseconds
 */
static long toEpochNanos(LocalDateTime timestamp) {
  long nanoInDay = timestamp.toLocalTime().toNanoOfDay();
  long nanosOfDay = toEpochNanos(timestamp.toLocalDate());
  return nanosOfDay + nanoInDay;
}

代码示例来源:origin: wildfly/wildfly

@Override
public void writeObject(ObjectOutput output, LocalDateTime dateTime) throws IOException {
  DefaultExternalizer.LOCAL_DATE.cast(LocalDate.class).writeObject(output, dateTime.toLocalDate());
  DefaultExternalizer.LOCAL_TIME.cast(LocalTime.class).writeObject(output, dateTime.toLocalTime());
}

代码示例来源:origin: prestodb/presto

@Test
public void testConvertTimestamp()
    throws SQLException
{
  LocalDateTime dateTime = LocalDateTime.of(2001, 5, 6, 12, 34, 56);
  Date sqlDate = Date.valueOf(dateTime.toLocalDate());
  Time sqlTime = Time.valueOf(dateTime.toLocalTime());
  Timestamp sqlTimestamp = Timestamp.valueOf(dateTime);
  java.util.Date javaDate = java.util.Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
  assertParameter(sqlTimestamp, Types.TIMESTAMP, (ps, i) -> ps.setTimestamp(i, sqlTimestamp));
  assertParameter(sqlTimestamp, Types.TIMESTAMP, (ps, i) -> ps.setObject(i, sqlTimestamp));
  assertParameter(new Timestamp(sqlDate.getTime()), Types.TIMESTAMP, (ps, i) -> ps.setObject(i, sqlDate, Types.TIMESTAMP));
  assertParameter(new Timestamp(sqlTime.getTime()), Types.TIMESTAMP, (ps, i) -> ps.setObject(i, sqlTime, Types.TIMESTAMP));
  assertParameter(sqlTimestamp, Types.TIMESTAMP, (ps, i) -> ps.setObject(i, sqlTimestamp, Types.TIMESTAMP));
  assertParameter(sqlTimestamp, Types.TIMESTAMP, (ps, i) -> ps.setObject(i, javaDate, Types.TIMESTAMP));
  assertParameter(sqlTimestamp, Types.TIMESTAMP, (ps, i) -> ps.setObject(i, dateTime, Types.TIMESTAMP));
  assertParameter(sqlTimestamp, Types.TIMESTAMP, (ps, i) -> ps.setObject(i, "2001-05-06 12:34:56", Types.TIMESTAMP));
}

代码示例来源:origin: debezium/debezium

@Test
public void shouldReturnLocalTimeInstanceWhenConvertingLocalDateTimeToLocalTime() {
  LocalDateTime now = LocalDateTime.now();
  assertThat(Conversions.toLocalTime(now)).isEqualTo(now.toLocalTime());
}

代码示例来源:origin: jtablesaw/tablesaw

@Test
public void testTime() {
  LocalDateTime dateTime = LocalDateTime.of(2018, 4, 10, 7, 30);
  startCol.append(dateTime);
  TimeColumn time = startCol.time();
  assertEquals(dateTime.toLocalTime(), time.get(0));
}

代码示例来源:origin: jtablesaw/tablesaw

@Test
public void testAsLocalDateTime() {
  LocalDateTime dateTime = LocalDateTime.now();
  long packed = pack(dateTime.toLocalDate(), dateTime.toLocalTime());
  LocalDateTime upacked = asLocalDateTime(packed);
  assertEquals(dateTime.getDayOfYear(), upacked.getDayOfYear());
  assertEquals(dateTime.getHour(), upacked.getHour());
  assertEquals(dateTime.getMinute(), upacked.getMinute());
  assertEquals(dateTime.getSecond(), upacked.getSecond());
}

代码示例来源:origin: jtablesaw/tablesaw

@Test
  public void testAtTime() {
    column1.appendCell("2013-10-23");
    column1.appendCell("12/24/1924");
    column1.appendCell("12-May-2015");
    column1.appendCell("14-Jan-2015");

    DateTimeColumn dateTimes = column1.atTime(LocalTime.NOON);
    assertNotNull(dateTimes);
    assertTrue(dateTimes.get(0).toLocalTime().equals(LocalTime.NOON));
  }
}

相关文章

LocalDateTime类方法