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


Java LocalTime.getHour方法代码示例

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


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

示例1: test_plusHours_fromZero

import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void test_plusHours_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().minusDays(3);
    LocalTime t = LocalTime.of(21, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.plusHours(i);
        t = t.plusHours(1);

        if (t.getHour() == 0) {
            d = d.plusDays(1);
        }

        assertEquals(dt.toLocalDate(), d);
        assertEquals(dt.toLocalTime(), t);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:TCKLocalDateTime.java

示例2: testRangeOfLocalTimes

import java.time.LocalTime; //导入方法依赖的package包/类
@Test(dataProvider = "LocalTimeRanges")
public void testRangeOfLocalTimes(LocalTime start, LocalTime end, Duration step, boolean parallel) {
    final boolean ascend = start.isBefore(end);
    final Range<LocalTime> range = Range.of(start, end, step, v -> v.getHour() == 6);
    final Array<LocalTime> array = range.toArray(parallel);
    final LocalTime first = array.first(v -> true).map(ArrayValue::getValue).get();
    final LocalTime last = array.last(v -> true).map(ArrayValue::getValue).get();
    Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_TIME);
    Assert.assertTrue(!array.style().isSparse());
    Assert.assertEquals(range.start(), start, "The range start");
    Assert.assertEquals(range.end(), end, "The range end");
    int index = 0;
    LocalTime value = first;
    while (ascend ? value.isBefore(last) : value.isAfter(last)) {
        final LocalTime actual = array.getValue(index);
        Assert.assertEquals(actual, value, "Value matches at " + index);
        Assert.assertTrue(ascend ? actual.compareTo(start) >= 0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + index);
        value = ascend ? value.plus(step) : value.minus(step);
        while (value.getHour() == 6) value = ascend ? value.plus(step) : value.minus(step);
        index++;
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:23,代码来源:RangeFilterTests.java

示例3: test_plusHours_fromOne

import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void test_plusHours_fromOne() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
    LocalDate d = base.toLocalDate().minusDays(3);
    LocalTime t = LocalTime.of(22, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.plusHours(i);

        t = t.plusHours(1);

        if (t.getHour() == 0) {
            d = d.plusDays(1);
        }

        assertEquals(dt.toLocalDate(), d);
        assertEquals(dt.toLocalTime(), t);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:TCKLocalDateTime.java

示例4: test_minusHours_fromZero

import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void test_minusHours_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().plusDays(2);
    LocalTime t = LocalTime.of(3, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.minusHours(i);
        t = t.minusHours(1);

        if (t.getHour() == 23) {
            d = d.minusDays(1);
        }

        assertEquals(dt.toLocalDate(), d, String.valueOf(i));
        assertEquals(dt.toLocalTime(), t);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TCKLocalDateTime.java

示例5: test_minusHours_fromOne

import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void test_minusHours_fromOne() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
    LocalDate d = base.toLocalDate().plusDays(2);
    LocalTime t = LocalTime.of(4, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.minusHours(i);

        t = t.minusHours(1);

        if (t.getHour() == 23) {
            d = d.minusDays(1);
        }

        assertEquals(dt.toLocalDate(), d, String.valueOf(i));
        assertEquals(dt.toLocalTime(), t);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:TCKLocalDateTime.java

示例6: actionPerformed

import java.time.LocalTime; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
	LocalTime localeTime = LocalTime.now();

	int hour = localeTime.getHour();
	int minute = localeTime.getMinute();
	int second = localeTime.getSecond();

	timeText.setText(String.format("%02d : %02d : %02d", hour, minute, second));
}
 
开发者ID:AitorB,项目名称:POPBL_V,代码行数:11,代码来源:Time.java

示例7: test_time_parse

import java.time.LocalTime; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_parse(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
    DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
    Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
    TemporalAccessor parsed = f.parse(text, pos);
    assertEquals(pos.getIndex(), text.length());
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(LocalTime.from(parsed), time);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:TCKLocalizedPrinterParser.java

示例8: test_time_print

import java.time.LocalTime; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
    DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
    Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
    String formatted = f.format(time);
    assertEquals(formatted, text);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:TCKLocalizedPrinterParser.java

示例9: isEqual

import java.time.LocalTime; //导入方法依赖的package包/类
private static boolean isEqual(LocalTime lt, java.sql.Time t) {
    return lt.getHour() == t.getHours() &&
           lt.getMinute() == t.getMinutes() &&
           lt.getSecond() == t.getSeconds();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:JavatimeTest.java

示例10: writeRule

import java.time.LocalTime; //导入方法依赖的package包/类
/**
 * Writes the state of the transition rule to the stream.
 *
 * @param rule  the transition rule, not null
 * @param out  the output stream, not null
 * @throws IOException if an error occurs
 */
static void writeRule(ZoneOffsetTransitionRule rule, DataOutput out) throws IOException {
    int month = rule.getMonth().getValue();
    byte dom = (byte)rule.getDayOfMonthIndicator();
    int dow = (rule.getDayOfWeek() == null ? -1 : rule.getDayOfWeek().getValue());
    LocalTime time = rule.getLocalTime();
    boolean timeEndOfDay = rule.isMidnightEndOfDay();
    TimeDefinition timeDefinition = rule.getTimeDefinition();
    ZoneOffset standardOffset = rule.getStandardOffset();
    ZoneOffset offsetBefore = rule.getOffsetBefore();
    ZoneOffset offsetAfter = rule.getOffsetAfter();

    int timeSecs = (timeEndOfDay ? 86400 : time.toSecondOfDay());
    int stdOffset = standardOffset.getTotalSeconds();
    int beforeDiff = offsetBefore.getTotalSeconds() - stdOffset;
    int afterDiff = offsetAfter.getTotalSeconds() - stdOffset;
    int timeByte = (timeSecs % 3600 == 0 ? (timeEndOfDay ? 24 : time.getHour()) : 31);
    int stdOffsetByte = (stdOffset % 900 == 0 ? stdOffset / 900 + 128 : 255);
    int beforeByte = (beforeDiff == 0 || beforeDiff == 1800 || beforeDiff == 3600 ? beforeDiff / 1800 : 3);
    int afterByte = (afterDiff == 0 || afterDiff == 1800 || afterDiff == 3600 ? afterDiff / 1800 : 3);
    int dowByte = (dow == -1 ? 0 : dow);
    int b = (month << 28) +                     // 4 bytes
            ((dom + 32) << 22) +                // 6 bytes
            (dowByte << 19) +                   // 3 bytes
            (timeByte << 14) +                  // 5 bytes
            (timeDefinition.ordinal() << 12) +  // 2 bytes
            (stdOffsetByte << 4) +              // 8 bytes
            (beforeByte << 2) +                 // 2 bytes
            afterByte;                          // 2 bytes
    out.writeInt(b);
    if (timeByte == 31) {
        out.writeInt(timeSecs);
    }
    if (stdOffsetByte == 255) {
        out.writeInt(stdOffset);
    }
    if (beforeByte == 3) {
        out.writeInt(offsetBefore.getTotalSeconds());
    }
    if (afterByte == 3) {
        out.writeInt(offsetAfter.getTotalSeconds());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:50,代码来源:ZoneRules.java

示例11: valueOf

import java.time.LocalTime; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code Time} from a {@link LocalTime} object
 * with the same hour, minute and second time value as the given
 * {@code LocalTime}.
 *
 * @param time a {@code LocalTime} to convert
 * @return a {@code Time} object
 * @exception NullPointerException if {@code time} is null
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Time valueOf(LocalTime time) {
    return new Time(time.getHour(), time.getMinute(), time.getSecond());
}
 
开发者ID:madHEYsia,项目名称:ClassroomFlipkart,代码行数:15,代码来源:Time.java

示例12: valueOf

import java.time.LocalTime; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code Time} from a {@link LocalTime} object
 * with the same hour, minute and second time value as the given
 * {@code LocalTime}. The nanosecond field from {@code LocalTime} is
 * not part of the newly created {@code Time} object.
 *
 * @param time a {@code LocalTime} to convert
 * @return a {@code Time} object
 * @exception NullPointerException if {@code time} is null
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Time valueOf(LocalTime time) {
    return new Time(time.getHour(), time.getMinute(), time.getSecond());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:Time.java


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