當前位置: 首頁>>代碼示例>>Java>>正文


Java Clock.fixed方法代碼示例

本文整理匯總了Java中java.time.Clock.fixed方法的典型用法代碼示例。如果您正苦於以下問題:Java Clock.fixed方法的具體用法?Java Clock.fixed怎麽用?Java Clock.fixed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.Clock的用法示例。


在下文中一共展示了Clock.fixed方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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());
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:18,代碼來源:TimeIntroduction.java

示例2: now_Clock_allSecsInDay_utc

import java.time.Clock; //導入方法依賴的package包/類
@Test
public void now_Clock_allSecsInDay_utc() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        ZonedDateTime test = ZonedDateTime.now(clock);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 123456789);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
        assertEquals(test.getZone(), ZoneOffset.UTC);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:TCKZonedDateTime.java

示例3: now_Clock_allSecsInDay_utc

import java.time.Clock; //導入方法依賴的package包/類
@Test
public void now_Clock_allSecsInDay_utc() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        LocalDateTime test = LocalDateTime.now(clock);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 123456789);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:TCKLocalDateTime.java

示例4: now_Clock_allSecsInDay_offset

import java.time.Clock; //導入方法依賴的package包/類
@Test
public void now_Clock_allSecsInDay_offset() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(instant.minusSeconds(OFFSET_PONE.getTotalSeconds()), OFFSET_PONE);
        LocalDateTime test = LocalDateTime.now(clock);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60) ? 1 : 2);
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 123456789);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:TCKLocalDateTime.java

示例5: now_Clock_allSecsInDay_utc

import java.time.Clock; //導入方法依賴的package包/類
@Test
public void now_Clock_allSecsInDay_utc() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        LocalDate test = LocalDate.now(clock);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:TCKLocalDate.java

示例6: now_Clock

import java.time.Clock; //導入方法依賴的package包/類
@Test
public void now_Clock() {
    Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC);
    Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
    MonthDay test = MonthDay.now(clock);
    assertEquals(test.getMonth(), Month.DECEMBER);
    assertEquals(test.getDayOfMonth(), 31);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:TCKMonthDay.java

示例7: now_Clock_allSecsInDay_utc

import java.time.Clock; //導入方法依賴的package包/類
@Test
public void now_Clock_allSecsInDay_utc() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant expected = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(expected, ZoneOffset.UTC);
        Instant test = Instant.now(clock);
        assertEquals(test, expected);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:10,代碼來源:TCKInstant.java

示例8: now_Clock

import java.time.Clock; //導入方法依賴的package包/類
@Test
public void now_Clock() {
    Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC);
    Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
    YearMonth test = YearMonth.now(clock);
    assertEquals(test.getYear(), 2010);
    assertEquals(test.getMonth(), Month.DECEMBER);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:TCKYearMonth.java

示例9: now_Clock_allSecsInDay_beforeEpoch

import java.time.Clock; //導入方法依賴的package包/類
@Test
public void now_Clock_allSecsInDay_beforeEpoch() {
    LocalTime expected = LocalTime.MIDNIGHT.plusNanos(123456789L);
    for (int i =-1; i >= -(24 * 60 * 60); i--) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        LocalDateTime test = LocalDateTime.now(clock);
        assertEquals(test.getYear(), 1969);
        assertEquals(test.getMonth(), Month.DECEMBER);
        assertEquals(test.getDayOfMonth(), 31);
        expected = expected.minusSeconds(1);
        assertEquals(test.toLocalTime(), expected);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:15,代碼來源:TCKLocalDateTime.java

示例10: now_Clock_maxYear

import java.time.Clock; //導入方法依賴的package包/類
@Test
public void now_Clock_maxYear() {
    Clock clock = Clock.fixed(MAX_INSTANT, ZoneOffset.UTC);
    LocalDate test = LocalDate.now(clock);
    assertEquals(test, MAX_DATE);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:7,代碼來源:TCKLocalDate.java

示例11: test_withZone_same

import java.time.Clock; //導入方法依賴的package包/類
public void test_withZone_same() {
    Clock test = Clock.fixed(INSTANT, PARIS);
    Clock changed = test.withZone(PARIS);
    assertSame(test, changed);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:TestClock_Fixed.java

示例12: now_Clock_tooBig

import java.time.Clock; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeException.class)
public void now_Clock_tooBig() {
    Clock clock = Clock.fixed(MAX_INSTANT.plusSeconds(24 * 60 * 60), ZoneOffset.UTC);
    LocalDate.now(clock);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:6,代碼來源:TCKLocalDate.java

示例13: now_Clock_maxYear

import java.time.Clock; //導入方法依賴的package包/類
@Test
public void now_Clock_maxYear() {
    Clock clock = Clock.fixed(MAX_INSTANT, ZoneOffset.UTC);
    LocalDateTime test = LocalDateTime.now(clock);
    assertEquals(test, MAX_DATE_TIME);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:TCKLocalDateTime.java

示例14: test_toString

import java.time.Clock; //導入方法依賴的package包/類
public void test_toString() {
    Clock test = Clock.fixed(INSTANT, PARIS);
    assertEquals(test.toString(), "FixedClock[2008-06-30T09:30:10.000000500Z,Europe/Paris]");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:TestClock_Fixed.java

示例15: test_withZone

import java.time.Clock; //導入方法依賴的package包/類
public void test_withZone() {
    Clock test = Clock.fixed(INSTANT, PARIS);
    Clock changed = test.withZone(MOSCOW);
    assertEquals(test.getZone(), PARIS);
    assertEquals(changed.getZone(), MOSCOW);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:TCKClock_Fixed.java


注:本文中的java.time.Clock.fixed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。