本文整理了Java中java.time.Duration.toString()
方法的一些代码示例,展示了Duration.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Duration.toString()
方法的具体详情如下:
包路径:java.time.Duration
类名称:Duration
方法名:toString
[英]A string representation of this duration using ISO-8601 seconds based representation, such as PT8H6M12.345S.
The format of the returned string will be PTnHnMnS, where n is the relevant hours, minutes or seconds part of the duration. Any fractional seconds are placed after a decimal point i the seconds section. If a section has a zero value, it is omitted. The hours, minutes and seconds will all have the same sign.
Examples:
"20.345 seconds" -> "PT20.345S
"15 minutes" (15 * 60 seconds) -> "PT15M"
"10 hours" (10 * 3600 seconds) -> "PT10H"
"2 days" (2 * 86400 seconds) -> "PT48H"
Note that multiples of 24 hours are not output as days to avoid confusion with Period.
[中]此持续时间的字符串表示,使用基于ISO-8601秒的表示法,如PT8H6M12。345S。
返回字符串的格式为PTnHnMnS,其中n是持续时间的相关小时、分钟或秒部分。任何小数秒都放在秒部分的小数点i之后。如果一个部分有一个零值,它将被忽略。小时、分钟和秒都有相同的符号。
示例:
"20.345 seconds" -> "PT20.345S
"15 minutes" (15 * 60 seconds) -> "PT15M"
"10 hours" (10 * 3600 seconds) -> "PT10H"
"2 days" (2 * 86400 seconds) -> "PT48H"
请注意,24小时的倍数不输出为天,以避免与周期混淆。
代码示例来源:origin: spring-projects/spring-framework
@Override
public String print(Duration object, Locale locale) {
return object.toString();
}
代码示例来源:origin: org.springframework/spring-context
@Override
public String print(Duration object, Locale locale) {
return object.toString();
}
代码示例来源:origin: org.springframework.boot/spring-boot
@Override
public String print(Duration value, ChronoUnit unit) {
return value.toString();
}
代码示例来源:origin: debezium/debezium
/**
* Compute the readable string representation of the supplied duration.
*
* @param duration the duration; may not be null
* @return the string representation; never null
*/
protected static String asString(Duration duration) {
return duration.toString().substring(2);
}
代码示例来源:origin: oracle/opengrok
@Override
public void serialize(
final Duration duration,
final JsonGenerator jsonGenerator,
final SerializerProvider serializerProvider
) throws IOException {
if (duration != null) {
jsonGenerator.writeString(duration.toString());
} else {
jsonGenerator.writeNull();
}
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
@SuppressWarnings("unchecked")
public <X> X unwrap(Duration duration, Class<X> type, WrapperOptions options) {
if ( duration == null ) {
return null;
}
if ( Duration.class.isAssignableFrom( type ) ) {
return (X) duration;
}
if ( String.class.isAssignableFrom( type ) ) {
return (X) duration.toString();
}
if ( Long.class.isAssignableFrom( type ) ) {
return (X) Long.valueOf( duration.toNanos() );
}
throw unknownUnwrap( type );
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public byte[] convert(Duration source) {
return fromString(source.toString());
}
}
代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-jsr310
@Override
public void serialize(Duration duration, JsonGenerator generator, SerializerProvider provider) throws IOException
{
if (useTimestamp(provider)) {
if (useNanoseconds(provider)) {
generator.writeNumber(DecimalUtils.toBigDecimal(
duration.getSeconds(), duration.getNano()
));
} else {
generator.writeNumber(duration.toMillis());
}
} else {
// Does not look like we can make any use of DateTimeFormatter here?
generator.writeString(duration.toString());
}
}
代码示例来源:origin: prestodb/presto
@Override
public void serialize(Duration duration, JsonGenerator generator, SerializerProvider provider) throws IOException
{
if (useTimestamp(provider)) {
if (useNanoseconds(provider)) {
generator.writeNumber(DecimalUtils.toBigDecimal(
duration.getSeconds(), duration.getNano()
));
} else {
generator.writeNumber(duration.toMillis());
}
} else {
// Does not look like we can make any use of DateTimeFormatter here?
generator.writeString(duration.toString());
}
}
代码示例来源:origin: ebean-orm/ebean
@Override
public String formatValue(Duration v) {
return v.toString();
}
代码示例来源:origin: ebean-orm/ebean
@Override
public void jsonWrite(JsonGenerator writer, Duration value) throws IOException {
writer.writeString(value.toString());
}
代码示例来源:origin: org.apache.hbase/hbase-client
/**
* A slower (but more easy-to-read) stringification
*/
public String toDescriptiveString() {
long relTime = System.currentTimeMillis() - stamp;
return hri.getRegionNameAsString()
+ " state=" + state + ", ts=" + new Date(stamp) + " (" +
java.time.Duration.ofMillis(relTime).toString() +
" ago), server=" + serverName;
}
代码示例来源:origin: apache/servicecomb-java-chassis
@Override
public void init(GlobalRegistry globalRegistry, EventBus eventBus, MetricsBootstrapConfig config) {
this.globalRegistry = globalRegistry;
// spectator move poll gauges from inline to background executor
// we need to set the interval to unify value
System.setProperty("spectator.api.gaugePollingFrequency", Duration.ofMillis(config.getMsPollInterval()).toString());
System.setProperty(SERVO_POLLERS, String.valueOf(config.getMsPollInterval()));
registry = new ServoRegistry();
globalRegistry.add(registry);
}
代码示例来源:origin: org.springframework.data/spring-data-couchbase
@Override
public String convert(Duration duration) {
return duration.toString();
}
}
代码示例来源:origin: io.github.amyassist/amy-http-server
/**
* @see javax.ws.rs.ext.ParamConverter#toString(java.lang.Object)
*/
@Override
public String toString(Duration value) {
return value.toString();
}
}
代码示例来源:origin: net.dongliu/gson-java8-datatype
@Override
public void write(JsonWriter out, Duration duration) throws IOException {
if (duration == null) {
out.nullValue();
return;
}
out.value(duration.toString());
}
代码示例来源:origin: org.springframework.data/spring-data-redis
@Override
public byte[] convert(Duration source) {
return fromString(source.toString());
}
}
代码示例来源:origin: org.eclipse/yasson
@Override
protected void serialize(Duration obj, JsonGenerator generator, Marshaller marshaller) {
generator.write(obj.toString());
}
}
代码示例来源:origin: spring-cloud/spring-cloud-stream
@Override
public String get(String key) {
String value = null;
if (key.equals(this.prefix() + ".step")) {
value = this.applicationMetricsProperties.getScheduleInterval().toString();
}
return value;
}
}
代码示例来源:origin: zeebe-io/zeebe
@Override
public String toString() {
if (period.isZero()) {
return duration.toString();
}
if (duration.isZero()) {
return period.toString();
}
return period.toString() + duration.toString().substring(1);
}
内容来源于网络,如有侵权,请联系作者删除!