當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。