当前位置: 首页>>代码示例>>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;未经允许,请勿转载。