本文整理匯總了Java中java.time.Clock.system方法的典型用法代碼示例。如果您正苦於以下問題:Java Clock.system方法的具體用法?Java Clock.system怎麽用?Java Clock.system使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.Clock
的用法示例。
在下文中一共展示了Clock.system方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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.systemUTC();
Clock b = Clock.systemUTC();
assertEquals(a.equals(a), true);
assertEquals(a.equals(b), true);
assertEquals(b.equals(a), true);
assertEquals(b.equals(b), true);
Clock c = Clock.system(PARIS);
Clock d = Clock.system(PARIS);
assertEquals(c.equals(c), true);
assertEquals(c.equals(d), true);
assertEquals(d.equals(c), true);
assertEquals(d.equals(d), true);
assertEquals(a.equals(c), false);
assertEquals(c.equals(a), false);
assertEquals(a.equals(null), false);
assertEquals(a.equals("other type"), false);
assertEquals(a.equals(Clock.fixed(Instant.now(), ZoneOffset.UTC)), false);
}
示例3: test_IsoChronology_dateNow
import java.time.Clock; //導入方法依賴的package包/類
@Test
public void test_IsoChronology_dateNow() {
ZoneId zoneId_paris = ZoneId.of("Europe/Paris");
Clock clock = Clock.system(zoneId_paris);
Chronology chrono = Chronology.of("ISO");
assertEquals(chrono.dateNow(), IsoChronology.INSTANCE.dateNow());
assertEquals(chrono.dateNow(zoneId_paris), IsoChronology.INSTANCE.dateNow(zoneId_paris));
assertEquals(chrono.dateNow(clock), IsoChronology.INSTANCE.dateNow(clock));
}
示例4: provider_sampleSystemUTC
import java.time.Clock; //導入方法依賴的package包/類
@DataProvider(name="sampleSystemUTC")
Object[][] provider_sampleSystemUTC() {
return new Object[][] {
{"Clock.systemUTC()#1", Clock.systemUTC()},
{"Clock.systemUTC()#2", Clock.systemUTC()},
{"Clock.system(ZoneOffset.UTC)#1", Clock.system(ZoneOffset.UTC)},
{"Clock.system(ZoneOffset.UTC)#2", Clock.system(ZoneOffset.UTC)}
};
}
示例5: test_MinguoChronology_dateNow
import java.time.Clock; //導入方法依賴的package包/類
@Test
public void test_MinguoChronology_dateNow() {
ZoneId zoneId_paris = ZoneId.of("Europe/Paris");
Clock clock = Clock.system(zoneId_paris);
Chronology chrono = Chronology.of("Minguo");
assertEquals(chrono.dateNow(), MinguoChronology.INSTANCE.dateNow());
assertEquals(chrono.dateNow(zoneId_paris), MinguoChronology.INSTANCE.dateNow(zoneId_paris));
assertEquals(chrono.dateNow(clock), MinguoChronology.INSTANCE.dateNow(clock));
}
示例6: test_JapaneseChronology_dateNow
import java.time.Clock; //導入方法依賴的package包/類
@Test
public void test_JapaneseChronology_dateNow() {
ZoneId zoneId_paris = ZoneId.of("Europe/Paris");
Clock clock = Clock.system(zoneId_paris);
Chronology chrono = Chronology.of("Japanese");
assertEquals(chrono.dateNow(), JapaneseChronology.INSTANCE.dateNow());
assertEquals(chrono.dateNow(zoneId_paris), JapaneseChronology.INSTANCE.dateNow(zoneId_paris));
assertEquals(chrono.dateNow(clock), JapaneseChronology.INSTANCE.dateNow(clock));
}
示例7: test_ThaiBuddhistChronology_dateNow
import java.time.Clock; //導入方法依賴的package包/類
@Test
public void test_ThaiBuddhistChronology_dateNow() {
ZoneId zoneId_paris = ZoneId.of("Europe/Paris");
Clock clock = Clock.system(zoneId_paris);
Chronology chrono = Chronology.of("ThaiBuddhist");
assertEquals(chrono.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow());
assertEquals(chrono.dateNow(zoneId_paris), ThaiBuddhistChronology.INSTANCE.dateNow(zoneId_paris));
assertEquals(chrono.dateNow(clock), ThaiBuddhistChronology.INSTANCE.dateNow(clock));
}
示例8: test_zoneId_nullZoneId
import java.time.Clock; //導入方法依賴的package包/類
@Test(expectedExceptions = NullPointerException.class)
public void test_zoneId_nullZoneId() {
Clock.system(null);
}
示例9: test_withZone
import java.time.Clock; //導入方法依賴的package包/類
public void test_withZone() {
Clock test = Clock.system(PARIS);
Clock changed = test.withZone(MOSCOW);
assertEquals(test.getZone(), PARIS);
assertEquals(changed.getZone(), MOSCOW);
}
示例10: test_withZone_equal
import java.time.Clock; //導入方法依賴的package包/類
public void test_withZone_equal() {
Clock test = Clock.system(PARIS);
Clock changed = test.withZone(PARIS);
assertEquals(changed.getZone(), PARIS);
}
示例11: test_withZone_same
import java.time.Clock; //導入方法依賴的package包/類
public void test_withZone_same() {
Clock test = Clock.system(PARIS);
Clock changed = test.withZone(PARIS);
assertSame(test, changed);
}
示例12: 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
}
示例13: test_tick_ClockDuration_zeroDuration
import java.time.Clock; //導入方法依賴的package包/類
public void test_tick_ClockDuration_zeroDuration() {
Clock underlying = Clock.system(PARIS);
Clock test = Clock.tick(underlying, Duration.ZERO);
assertSame(test, underlying); // spec says same
}
示例14: test_tick_ClockDuration_1nsDuration
import java.time.Clock; //導入方法依賴的package包/類
public void test_tick_ClockDuration_1nsDuration() {
Clock underlying = Clock.system(PARIS);
Clock test = Clock.tick(underlying, Duration.ofNanos(1));
assertSame(test, underlying); // spec says same
}