当前位置: 首页>>代码示例>>Java>>正文


Java LocalTime.toNanoOfDay方法代码示例

本文整理汇总了Java中java.time.LocalTime.toNanoOfDay方法的典型用法代码示例。如果您正苦于以下问题:Java LocalTime.toNanoOfDay方法的具体用法?Java LocalTime.toNanoOfDay怎么用?Java LocalTime.toNanoOfDay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.LocalTime的用法示例。


在下文中一共展示了LocalTime.toNanoOfDay方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: now

import java.time.LocalTime; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unused")
public void now() {
    // Warmup the TimeZone data so the following test does not include
    // one-time initialization
    LocalTime.now(Clock.systemDefaultZone());

    long diff = Integer.MAX_VALUE;
    for (int i = 0; i < 2; i++) {
        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
        LocalTime test = LocalTime.now();
        diff = test.toNanoOfDay() - expected.toNanoOfDay();
        // Normalize for wrap-around midnight
        diff = Math.floorMod(NANOS_PER_DAY + diff, NANOS_PER_DAY);
        if (diff < 100000000) {
            break;
        }
        // A second iteration may be needed if the clock changed
        // due to a DST change between the two calls to now.
    }
    assertTrue(diff < 100000000,   // less than 0.1 sec
            "LocalTime.now  vs LocalTime.now(Clock.systemDefaultZone()) not close");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:TestLocalTime.java

示例2: getTimeLocation

import java.time.LocalTime; //导入方法依赖的package包/类
public static double getTimeLocation(DayViewBase view, LocalTime time, boolean prefHeight) {
    LocalTime startTime = view.getStartTime();
    LocalTime endTime = view.getEndTime();
    double availableHeight = view.getHeight();
    if (prefHeight) {
        availableHeight = view.prefHeight(-1);
    }
    EarlyLateHoursStrategy strategy = view.getEarlyLateHoursStrategy();

    switch (strategy) {
        case SHOW:
            long startNano = LocalTime.MIN.toNanoOfDay();
            long endNano = LocalTime.MAX.toNanoOfDay();

            double npp = (endNano - startNano) / availableHeight;

            return ((int) ((time.toNanoOfDay() - startNano) / npp)) + .5;
        case HIDE:
            if (time.isBefore(startTime)) {
                return -1;
            }

            if (time.isAfter(endTime)) {
                return availableHeight;
            }

            startNano = startTime.toNanoOfDay();
            endNano = endTime.toNanoOfDay();

            npp = (endNano - startNano) / availableHeight;

            return ((int) ((time.toNanoOfDay() - startNano) / npp)) + .5;
        case SHOW_COMPRESSED:
            long earlyHours = ChronoUnit.HOURS
                    .between(LocalTime.MIN, startTime);
            long lateHours = ChronoUnit.HOURS.between(endTime, LocalTime.MAX) + 1;
            double hourHeightCompressed = view.getHourHeightCompressed();
            double earlyHeight = hourHeightCompressed * earlyHours;
            double lateHeight = hourHeightCompressed * lateHours;

            if (time.isBefore(startTime)) {
                /*
                 * Early compressed hours.
                 */
                startNano = LocalTime.MIN.toNanoOfDay();
                endNano = startTime.toNanoOfDay();

                npp = (endNano - startNano) / earlyHeight;

                return ((int) ((time.toNanoOfDay() - startNano) / npp)) + .5;
            } else if (time.isAfter(endTime)) {
                /*
                 * Late compressed hours.
                 */
                startNano = endTime.toNanoOfDay();
                endNano = LocalTime.MAX.toNanoOfDay();

                npp = (endNano - startNano) / lateHeight;

                return ((int) ((time.toNanoOfDay() - startNano) / npp))
                        + (availableHeight - lateHeight) + .5;
            } else {
                /*
                 * Regular hours.
                 */
                startNano = startTime.toNanoOfDay();
                endNano = endTime.toNanoOfDay();
                npp = (endNano - startNano)
                        / (availableHeight - earlyHeight - lateHeight);

                return earlyHeight
                        + ((int) ((time.toNanoOfDay() - startNano) / npp)) + .5;
            }
        default:
            return 0;
    }
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:78,代码来源:ViewHelper.java

示例3: getCode

import java.time.LocalTime; //导入方法依赖的package包/类
@Override
public final long getCode(LocalTime value) {
    return value == null ? Long.MIN_VALUE : value.toNanoOfDay();
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:5,代码来源:LongCoding.java


注:本文中的java.time.LocalTime.toNanoOfDay方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。