java.time.Duration compareTo()方法
java.time.Duration.compareTo() 方法将此持续时间与指定的持续时间进行比较。
1 语法
public int compareTo(Duration otherDuration)
2 参数
otherDuration :要比较的其他持续时间,而不是null。
3 返回值
比较器值,如果更小则为负,如果更大则为正。
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* java.time.Duration compareTo()方法
*/
import java.time.Duration;
import java.time.LocalTime;
public class DurationDemo {
public static void main(String[] args) {
Duration duration = Duration.between(LocalTime.NOON,LocalTime.MAX);
Duration duration1 = Duration.between(LocalTime.NOON,LocalTime.MIN);
System.out.println(duration.compareTo(duration1));
System.out.println(duration1.compareTo(duration1));
System.out.println(duration1.compareTo(duration));
}
}
输出结果为:
1
0
-1
热门文章
优秀文章