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


Java LocalTime.plusNanos方法代碼示例

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


在下文中一共展示了LocalTime.plusNanos方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: test_plusNanos_halfABillion

import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void test_plusNanos_halfABillion() {
    LocalTime t = LocalTime.MIDNIGHT;
    int hour = 0;
    int min = 0;
    int sec = 0;
    int nanos = 0;
    for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
        t = t.plusNanos(500000000);
        nanos += 500000000;
        if (nanos == 1000000000) {
            sec++;
            nanos = 0;
        }
        if (sec == 60) {
            min++;
            sec = 0;
        }
        if (min == 60) {
            hour++;
            min = 0;
        }
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
        assertEquals(t.getNano(), nanos);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:29,代碼來源:TCKLocalTime.java

示例2: test_plusNanos_fromZero

import java.time.LocalTime; //導入方法依賴的package包/類
@Test(dataProvider="plusNanos_fromZero")
public void test_plusNanos_fromZero(long nanoseconds, int hour, int min, int sec, int nanos) {
    LocalTime base = LocalTime.MIDNIGHT;
    LocalTime t = base.plusNanos(nanoseconds);

    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:11,代碼來源:TCKLocalTime.java

示例3: test_toNanoOfDay

import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void test_toNanoOfDay() {
    LocalTime t = LocalTime.of(0, 0);
    for (int i = 0; i < 1000000; i++) {
        assertEquals(t.toNanoOfDay(), i);
        t = t.plusNanos(1);
    }
    t = LocalTime.of(0, 0);
    for (int i = 1; i <= 1000000; i++) {
        t = t.minusNanos(1);
        assertEquals(t.toNanoOfDay(), 24 * 60 * 60 * 1000000000L - i);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:TCKLocalTime.java

示例4: test_toNanoOfDay_fromNanoOfDay_symmetry

import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void test_toNanoOfDay_fromNanoOfDay_symmetry() {
    LocalTime t = LocalTime.of(0, 0);
    for (int i = 0; i < 1000000; i++) {
        assertEquals(LocalTime.ofNanoOfDay(t.toNanoOfDay()), t);
        t = t.plusNanos(1);
    }
    t = LocalTime.of(0, 0);
    for (int i = 1; i <= 1000000; i++) {
        t = t.minusNanos(1);
        assertEquals(LocalTime.ofNanoOfDay(t.toNanoOfDay()), t);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:TCKLocalTime.java


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