java.time.ZoneOffset compareTo()方法
java.time.ZoneOffset.compareTo(ZoneOffset otherZoneOffset)方法将此ZoneOffset与指定的ZoneOffset进行比较。
1 语法
public int compareTo(ZoneOffset otherZoneOffset)
2 参数
otherZoneOffset:要比较的其他ZoneOffset,而不是null。
3 返回值
比较器值,如果更小则返回为负值,如果大则返回为正值。
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* java.time.ZoneOffset compareTo()方法
*/
import java.time.ZoneOffset;
public class ZoneOffsetDemo {
public static void main(String[] args) {
ZoneOffset zoneOffset = ZoneOffset.of("Z");
System.out.println("ZoneOffset #1: " + zoneOffset);
ZoneOffset zoneOffset1 = ZoneOffset.of("+02:00");
System.out.println("ZoneOffset #2: " + zoneOffset1);
int result = zoneOffset.compareTo(zoneOffset1);
System.out.println(result > 1 ? "ZoneOffset #1 is greater than ZoneOffset #2."
:"ZoneOffset #2 is greater than ZoneOffset #1.");
}
}
输出结果为:
ZoneOffset #1: Z
ZoneOffset #2: +02:00
ZoneOffset #1 is greater than ZoneOffset #2.
热门文章
优秀文章