java.time.LocalTime.getSecond()方法的使用及代码示例

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

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

LocalTime.getSecond介绍

[英]Gets the second-of-minute field.
[中]获取分钟数字段的秒数。

代码示例

代码示例来源:origin: org.assertj/assertj-core

/**
 * Returns true if both localtime are in the same year, month and day of month, hour, minute and second, false
 * otherwise.
 *
 * @param actual the actual localtime. expected not be null
 * @param other the other localtime. expected not be null
 * @return true if both localtime are in the same year, month and day of month, hour, minute and second, false
 *         otherwise.
 */
private static boolean areEqualIgnoringNanos(LocalTime actual, LocalTime other) {
 return areEqualIgnoringSeconds(actual, other) && actual.getSecond() == other.getSecond();
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Returns true if both localtime are in the same year, month and day of month, hour, minute and second, false
 * otherwise.
 *
 * @param actual the actual localtime. expected not be null
 * @param other the other localtime. expected not be null
 * @return true if both localtime are in the same year, month and day of month, hour, minute and second, false
 *         otherwise.
 */
private static boolean areEqualIgnoringNanos(LocalTime actual, LocalTime other) {
 return areEqualIgnoringSeconds(actual, other) && actual.getSecond() == other.getSecond();
}

代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-jsr310

private final void _serializeAsArrayContents(LocalTime value, JsonGenerator g,
    SerializerProvider provider) throws IOException
{
  g.writeNumber(value.getHour());
  g.writeNumber(value.getMinute());
  int secs = value.getSecond();
  int nanos = value.getNano();
  if ((secs > 0) || (nanos > 0))
  {
    g.writeNumber(secs);
    if (nanos > 0) {
      if (useNanoseconds(provider)) {
        g.writeNumber(nanos);
      } else {
        g.writeNumber(value.get(ChronoField.MILLI_OF_SECOND));
      }
    }
  }
}

代码示例来源:origin: org.postgresql/postgresql

private static void appendTime(StringBuilder sb, LocalTime localTime) {
 int hours = localTime.getHour();
 int minutes = localTime.getMinute();
 int seconds = localTime.getSecond();
 int nanos = localTime.getNano();
 appendTime(sb, hours, minutes, seconds, nanos);
}

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

private final void _serializeAsArrayContents(LocalTime value, JsonGenerator g,
    SerializerProvider provider) throws IOException
{
  g.writeNumber(value.getHour());
  g.writeNumber(value.getMinute());
  int secs = value.getSecond();
  int nanos = value.getNano();
  if ((secs > 0) || (nanos > 0))
  {
    g.writeNumber(secs);
    if (nanos > 0) {
      if (useNanoseconds(provider)) {
        g.writeNumber(nanos);
      } else {
        g.writeNumber(value.get(ChronoField.MILLI_OF_SECOND));
      }
    }
  }
}

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

@SuppressWarnings("deprecation")
@Test
public void shouldReturnLocalDateTimeInstanceWhenConvertingSqlTimeToLocalDateTime() {
  LocalTime now = LocalTime.now();
  java.sql.Time time = new java.sql.Time(now.getHour(),now.getMinute(),now.getSecond()); // 0 nanos!
  assertThat(Conversions.toLocalDateTime(time)).isEqualTo(LocalDateTime.of(Conversions.EPOCH, now.withNano(0)));
}

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

@Test
public void testGetSecond() {
  LocalTime now = LocalTime.now();
  assertEquals(now.getSecond(), getSecond(pack(now)));
}

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

@SuppressWarnings("deprecation")
@Test
public void shouldReturnLocalTimeInstanceWhenConvertingUtilTimeToLocalTime() {
  LocalTime now = LocalTime.now();
  java.util.Date date = new java.util.Date(0,0,1,now.getHour(),now.getMinute(),now.getSecond()); // 0 nanos!
  assertThat(Conversions.toLocalTime(date)).isEqualTo(now.withNano(0));
}

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

@SuppressWarnings("deprecation")
@Test
public void shouldReturnLocalTimeInstanceWhenConvertingSqlTimeToLocalTime() {
  LocalTime now = LocalTime.now();
  java.sql.Time time = new java.sql.Time(now.getHour(),now.getMinute(),now.getSecond()); // 0 nanos!
  assertThat(Conversions.toLocalTime(time)).isEqualTo(now.withNano(0));
}

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

@Test
public void testPack() {
  LocalTime time = LocalTime.now();
  int packed = pack(time);
  LocalTime t1 = asLocalTime(PackedLocalDateTime.time(packed));
  assertNotNull(t1);
  assertEquals(time.getHour(), t1.getHour());
  assertEquals(time.getMinute(), t1.getMinute());
  assertEquals(time.getSecond(), t1.getSecond());
  assertEquals(time.get(ChronoField.MILLI_OF_SECOND), t1.get(ChronoField.MILLI_OF_SECOND));
}

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

private void assertTimeEquals(LocalTime localTime2, int packedTime2) {
    assertEquals(localTime2.getHour(), getHour(packedTime2));
    assertEquals(localTime2.getMinute(), getMinute(packedTime2));
    assertEquals(localTime2.getSecond(), getSecond(packedTime2));
    assertEquals(localTime2.getNano(), getNano(packedTime2));
  }
}

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

@Test
public void testConstructors1() {
  LocalTime localTime = LocalTime.of(5, 11, 36);
  int packedTime = pack(localTime);
  int packedTime2 = of(5, 11, 36);
  assertEquals(
      getMillisecondOfDay(packedTime),
      getMillisecondOfDay(packedTime2)
      );
  assertEquals(localTime.getHour(), getHour(packedTime2));
  assertEquals(localTime.getMinute(), getMinute(packedTime2));
  assertEquals(localTime.getSecond(), getSecond(packedTime2));
}

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

@Test
public void testConstructors2() {
  LocalTime localTime = LocalTime.of(5, 11);
  int packedTime = pack(localTime);
  int packedTime2 = of(5, 11);
  assertEquals(
      getMillisecondOfDay(packedTime),
      getMillisecondOfDay(packedTime2)
      );
  assertEquals(localTime.getHour(), getHour(packedTime2));
  assertEquals(localTime.getMinute(), getMinute(packedTime2));
  assertEquals(localTime.getSecond(), getSecond(packedTime2));
}

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

@Test
public void testTruncatedTo() {
  fillColumn();
  TimeColumn column2 = column1.truncatedTo(ChronoUnit.HOURS);
  assertEquals(column1.get(0).getHour(), column2.get(0).getHour());
  assertEquals(0, column2.get(0).getMinute());
  assertEquals(0, column2.get(0).getSecond());
  assertEquals(0, column2.get(0).getNano());
  assertEquals(TimeColumnType.missingValueIndicator(), column2.getIntInternal(2));
}

代码示例来源:origin: benas/random-beans

public static org.joda.time.LocalTime toJodaLocalTime(final LocalTime localTime) {
  return new org.joda.time.LocalTime(localTime.getHour(), localTime.getMinute(), localTime.getSecond());
}

代码示例来源:origin: benas/random-beans

public static org.joda.time.DateTime toJodaDateTime(final LocalDate localDate, final LocalTime localTime) {
  return new DateTime(localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth(),
      localTime.getHour(), localTime.getMinute(), localTime.getSecond());
}

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

assertThat(c2Time.getHour()).isEqualTo(17);
assertThat(c2Time.getMinute()).isEqualTo(51);
assertThat(c2Time.getSecond()).isEqualTo(4);
assertThat(c2Time.getNano()).isEqualTo((int) TimeUnit.MILLISECONDS.toNanos(780));
assertThat(io.debezium.time.Time.toMilliOfDay(c2Time, ADJUSTER)).isEqualTo((int) c2.getTime());
assertThat(c2Time.getHour()).isEqualTo(0);
assertThat(c2Time.getMinute() == 0 || c2Time.getMinute() == 1).isTrue();
assertThat(c2Time.getSecond()).isEqualTo(0);
assertThat(c2Time.getNano()).isEqualTo(0);
assertThat(io.debezium.time.Time.toMilliOfDay(c2Time, ADJUSTER)).isEqualTo((int) c2.getTime());

代码示例来源:origin: benas/random-beans

public static org.joda.time.LocalDateTime toJodaLocalDateTime(final LocalDate localDate, final LocalTime localTime) {
    return new LocalDateTime(localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth(),
        localTime.getHour(), localTime.getMinute(), localTime.getSecond());
  }
}

代码示例来源:origin: org.jadira.usertype/usertype.extended

@Override
public Time toNonNullValue(LocalTime value) {
  ZoneOffset currentDatabaseZone = databaseZone == null ? getDefault() : databaseZone;
  
  OffsetDateTime zonedValue = LocalDateTime.of(
        1970, 1, 1, value.getHour(), value.getMinute(), value.getSecond(), value.getNano()
      ).atOffset(currentDatabaseZone);
  
  final Time time = new Time(zonedValue.toInstant().toEpochMilli());
  return time;
}

代码示例来源:origin: hprose/hprose-java

@Override
  public final void serialize(Writer writer, LocalTime time) throws IOException {
    super.serialize(writer, time);
    OutputStream stream = writer.stream;
    ValueWriter.writeTime(stream, time.getHour(), time.getMinute(), time.getSecond(), 0, false, true);
    ValueWriter.writeNano(stream, time.getNano());
    stream.write(TagSemicolon);
  }
}

相关文章