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

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

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

LocalTime.toString介绍

[英]Outputs this time as a String, such as 10:15.

The output will be one of the following ISO-8601 formats:

  • HH:mm
  • HH:mm:ss
  • HH:mm:ss.SSS
  • HH:mm:ss.SSSSSS
  • HH:mm:ss.SSSSSSSSS

The format used will be the shortest that outputs the full value of the time where the omitted parts are implied to be zero.
[中]这次以字符串形式输出,例如10:15。
输出将是以下ISO-8601格式之一:
*嗯
*HH:mm:ss
*HH:mm:ss。SSS
*HH:mm:ss。SSSS
*HH:mm:ss。SSSSSSSSS
所使用的格式将是最短的,用于输出省略部分暗示为零的时间的完整值。

代码示例

代码示例来源:origin: oblac/jodd

@Override
public void set(final PreparedStatement st, final int index, final LocalTime value, final int dbSqlType) throws SQLException {
  if (value == null) {
    st.setNull(index, dbSqlType);
    return;
  }
  if (dbSqlType == Types.VARCHAR) {
    st.setString(index, value.toString());
    return;
  }
  st.setLong(index, value.toSecondOfDay());
}

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

@Override
  public byte[] convert(LocalTime source) {
    return fromString(source.toString());
  }
}

代码示例来源:origin: stackoverflow.com

LocalTime time = new LocalTime(12, 20);
String formatted = time.toString("HH:mm");

代码示例来源:origin: OpenHFT/Chronicle-Queue

public static String formatRollTime(final LocalTime time, final ZoneId zoneId) {
  return String.format("%s;%s;%s", Type.ROLL_TIME.name(), time.toString(), zoneId.toString());
}

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

@Override
public void stringifyValue(StringBuilder buffer, int row) {
 if (isRepeating) {
  row = 0;
 }
 if (noNulls || !isNull[row]) {
  scratchTimestamp.setTime(time[row]);
  scratchTimestamp.setNanos(nanos[row]);
  if (isUTC) {
   LocalDateTime ts =
     LocalDateTime.ofInstant(Instant.ofEpochMilli(time[row]), ZoneOffset.UTC).withNano(nanos[row]);
   buffer.append(ts.toLocalDate().toString() + ' ' + ts.toLocalTime().toString());
  } else {
   buffer.append(scratchTimestamp.toString());
  }
 } else {
  buffer.append("null");
 }
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

public static QueueOffsetSpec ofRollTime(final LocalTime time, final ZoneId zoneId) {
  return new QueueOffsetSpec(Type.ROLL_TIME, new String[]{time.toString(), zoneId.toString()});
}

代码示例来源:origin: stackoverflow.com

System.out.println("LocalTime : " + localTime.toString());
System.out.println("localDate : " + localDate.toString());
System.out.println("dateTime : " + dateTime.toString());

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

@Override
public void writeLocalTime( LocalTime localTime ) throws RuntimeException
{
  append( "{localTime: " );
  append( quote( localTime.toString() ) );
  append( "}" );
}

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

/**
 * Returns a DateTime column where each value consists of the dates from this column combined with the corresponding
 * times from the other column
 */
default DateTimeColumn atTime(LocalTime time) {
  Preconditions.checkNotNull(time);
  DateTimeColumn newColumn = DateTimeColumn.create(this.name() + " " + time.toString());
  for (int r = 0; r < this.size(); r++) {
    int c1 = this.getIntInternal(r);
    if (DateColumn.valueIsMissing(c1)) {
    newColumn.appendMissing();
    } else {
      LocalDate value1 = PackedLocalDate.asLocalDate(c1);
      newColumn.appendInternal(PackedLocalDateTime.pack(value1, time));
    }
  }
  return newColumn;
}

代码示例来源:origin: ebean-orm/ebean

@Override
public String formatValue(LocalTime v) {
 return v.toString();
}

代码示例来源:origin: stackoverflow.com

int millis = 5000;
int seconds = millis / 1000; // Maybe no need to divide if the input is in seconds
LocalTime timeOfDay = LocalTime.ofSecondOfDay(seconds);
String time = timeOfDay.toString();

代码示例来源:origin: ebean-orm/ebean

@Override
public void jsonWrite(JsonGenerator writer, LocalTime value) throws IOException {
 writer.writeString(value.toString());
}

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

Assert.assertThat(withJoda.getT().toString(), is(withJsr310.getT().toString()));
Assert.assertThat(withJoda.getTs().toString(), is(withJsr310.getTs().toString()));
Assert.assertThat(withJoda.getDec(), comparesEqualTo(withJsr310.getDec()));

代码示例来源:origin: com.moodysalem.java/jaxrs-lib

@Override
  public String toString(LocalTime value) {
    if (value != null) {
      return value.toString();
    }
    return null;
  }
}

代码示例来源:origin: stackoverflow.com

public class MyLocalTimeSerializer extends JsonSerializer<LocalDate> {

  @Override
  public void serialize(
      LocalTime time, 
      JsonGenerator gen, 
      SerializerProvider arg2) throws IOException, JsonProcessingException {
    gen.writeString(time.toString("HH:mm"));
  }

}

代码示例来源:origin: org.jodd/jodd-db

@Override
public void set(final PreparedStatement st, final int index, final LocalTime value, final int dbSqlType) throws SQLException {
  if (value == null) {
    st.setNull(index, dbSqlType);
    return;
  }
  if (dbSqlType == Types.VARCHAR) {
    st.setString(index, value.toString());
    return;
  }
  st.setLong(index, value.toSecondOfDay());
}

代码示例来源:origin: ch.rasc/bsoncodec

@Override
public void encode(BsonWriter writer, LocalTime value,
    EncoderContext encoderContext) {
  writer.writeString(value.toString());
}

代码示例来源:origin: stackoverflow.com

LocalTime start = LocalTime.parse( "08:00" );
int hours = 2;
LocalTime time = start;
for ( int i = 0 ; i <= hours ; i++ ) {
  String output = time.toString();
  // Set up next loop.
  time = time.plusHours( 1 );
}

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

@Override
  public byte[] convert(LocalTime source) {
    return fromString(source.toString());
  }
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Outputs this date-time as a {@code String}.
 * <p>
 * The output will include the full local date-time and the chronology ID.
 *
 * @return a string representation of this date-time, not null
 */
@Override
public String toString() {
  return toLocalDate().toString() + 'T' + toLocalTime().toString();
}

相关文章