本文整理汇总了Java中java.time.Clock.offset方法的典型用法代码示例。如果您正苦于以下问题:Java Clock.offset方法的具体用法?Java Clock.offset怎么用?Java Clock.offset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Clock
的用法示例。
在下文中一共展示了Clock.offset方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testClock
import java.time.Clock; //导入方法依赖的package包/类
public static void testClock() throws InterruptedException {
//时钟提供给我们用于访问某个特定 时区的 瞬时时间、日期 和 时间的。
Clock c1 = Clock.systemUTC(); //系统默认UTC时钟(当前瞬时时间 System.currentTimeMillis())
System.out.println(c1.millis()); //每次调用将返回当前瞬时时间(UTC)
Clock c2 = Clock.systemDefaultZone(); //系统默认时区时钟(当前瞬时时间)
Clock c31 = Clock.system(ZoneId.of("Europe/Paris")); //巴黎时区
System.out.println(c31.millis()); //每次调用将返回当前瞬时时间(UTC)
Clock c32 = Clock.system(ZoneId.of("Asia/Shanghai"));//上海时区
System.out.println(c32.millis());//每次调用将返回当前瞬时时间(UTC)
Clock c4 = Clock.fixed(Instant.now(), ZoneId.of("Asia/Shanghai"));//固定上海时区时钟
System.out.println(c4.millis());
Thread.sleep(1000);
System.out.println(c4.millis()); //不变 即时钟时钟在那一个点不动
Clock c5 = Clock.offset(c1, Duration.ofSeconds(2)); //相对于系统默认时钟两秒的时钟
System.out.println(c1.millis());
System.out.println(c5.millis());
}
示例2: test_equals
import java.time.Clock; //导入方法依赖的package包/类
public void test_equals() {
Clock a = Clock.offset(Clock.system(PARIS), OFFSET);
Clock b = Clock.offset(Clock.system(PARIS), OFFSET);
assertEquals(a.equals(a), true);
assertEquals(a.equals(b), true);
assertEquals(b.equals(a), true);
assertEquals(b.equals(b), true);
Clock c = Clock.offset(Clock.system(MOSCOW), OFFSET);
assertEquals(a.equals(c), false);
Clock d = Clock.offset(Clock.system(PARIS), OFFSET.minusNanos(1));
assertEquals(a.equals(d), false);
assertEquals(a.equals(null), false);
assertEquals(a.equals("other type"), false);
assertEquals(a.equals(Clock.systemUTC()), false);
}
示例3: test_offset_ClockDuration
import java.time.Clock; //导入方法依赖的package包/类
public void test_offset_ClockDuration() {
Clock test = Clock.offset(Clock.fixed(INSTANT, PARIS), OFFSET);
//System.out.println(test.instant());
//System.out.println(INSTANT.plus(OFFSET));
assertEquals(test.instant(), INSTANT.plus(OFFSET));
assertEquals(test.getZone(), PARIS);
}
示例4: test_hashCode
import java.time.Clock; //导入方法依赖的package包/类
public void test_hashCode() {
Clock a = Clock.offset(Clock.system(PARIS), OFFSET);
Clock b = Clock.offset(Clock.system(PARIS), OFFSET);
assertEquals(a.hashCode(), a.hashCode());
assertEquals(a.hashCode(), b.hashCode());
Clock c = Clock.offset(Clock.system(MOSCOW), OFFSET);
assertEquals(a.hashCode() == c.hashCode(), false);
Clock d = Clock.offset(Clock.system(PARIS), OFFSET.minusNanos(1));
assertEquals(a.hashCode() == d.hashCode(), false);
}
示例5: test_offset_ClockDuration_zeroDuration
import java.time.Clock; //导入方法依赖的package包/类
public void test_offset_ClockDuration_zeroDuration() {
Clock underlying = Clock.system(PARIS);
Clock test = Clock.offset(underlying, Duration.ZERO);
assertSame(test, underlying); // spec says same
}
示例6: test_offset_ClockDuration_nullClock
import java.time.Clock; //导入方法依赖的package包/类
@Test(expectedExceptions = NullPointerException.class)
public void test_offset_ClockDuration_nullClock() {
Clock.offset(null, Duration.ZERO);
}
示例7: test_offset_ClockDuration_nullDuration
import java.time.Clock; //导入方法依赖的package包/类
@Test(expectedExceptions = NullPointerException.class)
public void test_offset_ClockDuration_nullDuration() {
Clock.offset(Clock.systemUTC(), null);
}
示例8: test_withZone
import java.time.Clock; //导入方法依赖的package包/类
public void test_withZone() {
Clock test = Clock.offset(Clock.system(PARIS), OFFSET);
Clock changed = test.withZone(MOSCOW);
assertEquals(test.getZone(), PARIS);
assertEquals(changed.getZone(), MOSCOW);
}
示例9: test_toString
import java.time.Clock; //导入方法依赖的package包/类
public void test_toString() {
Clock test = Clock.offset(Clock.systemUTC(), OFFSET);
assertEquals(test.toString(), "OffsetClock[SystemClock[Z],PT2S]");
}
示例10: test_withZone_same
import java.time.Clock; //导入方法依赖的package包/类
public void test_withZone_same() {
Clock test = Clock.offset(Clock.system(PARIS), OFFSET);
Clock changed = test.withZone(PARIS);
assertSame(test, changed);
}
示例11: test_withZone_equal
import java.time.Clock; //导入方法依赖的package包/类
public void test_withZone_equal() {
Clock test = Clock.offset(Clock.system(PARIS), OFFSET);
Clock changed = test.withZone(PARIS);
assertEquals(test, changed);
}