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


Java ZonedDateTime.getYear方法代碼示例

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


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

示例1: testParseUTCDateTime

import java.time.ZonedDateTime; //導入方法依賴的package包/類
@Test
public void testParseUTCDateTime() throws Exception {
    // ARRANGE
    String date = "2016-12-31T12:13:14Z";

    // ACT
    ZonedDateTime dateTime = FormatUtils.parseUTCTime(date);
    int year = dateTime.getYear();
    int dayOfMonth = dateTime.getDayOfMonth();
    int hour = dateTime.getHour();

    // ASSERT
    assertThat(year, equalTo(2016));
    assertThat(dayOfMonth, equalTo(31));
    assertThat(hour, equalTo(12));
}
 
開發者ID:salesforce,項目名稱:pyplyn,代碼行數:17,代碼來源:FormatUtilsTest.java

示例2: testParseNonGMTDateTime

import java.time.ZonedDateTime; //導入方法依賴的package包/類
@Test
public void testParseNonGMTDateTime() throws Exception {
    // ARRANGE
    String date = "2016-12-31T12:13:14-07:00";

    // ACT
    ZonedDateTime dateTime = FormatUtils.parseUTCTime(date);
    int year = dateTime.getYear();
    int dayOfMonth = dateTime.getDayOfMonth();
    int hour = dateTime.getHour();

    // ASSERT
    assertThat(year, equalTo(2016));
    assertThat(dayOfMonth, equalTo(31));
    assertThat(hour, equalTo(19));
}
 
開發者ID:salesforce,項目名稱:pyplyn,代碼行數:17,代碼來源:FormatUtilsTest.java

示例3: test_Paris_getStandardOffset

import java.time.ZonedDateTime; //導入方法依賴的package包/類
public void test_Paris_getStandardOffset() {
    ZoneRules test = europeParis();
    ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC);
    while (zdt.getYear() < 2010) {
        Instant instant = zdt.toInstant();
        if (zdt.toLocalDate().isBefore(LocalDate.of(1911, 3, 11))) {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, 9, 21));
        } else if (zdt.toLocalDate().isBefore(LocalDate.of(1940, 6, 14))) {
            assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
        } else if (zdt.toLocalDate().isBefore(LocalDate.of(1944, 8, 25))) {
            assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
        } else if (zdt.toLocalDate().isBefore(LocalDate.of(1945, 9, 16))) {
            assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
        } else {
            assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
        }
        zdt = zdt.plusMonths(6);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:TCKZoneRules.java

示例4: encodeAsHex

import java.time.ZonedDateTime; //導入方法依賴的package包/類
public static String encodeAsHex(LocalDateTime dateTime) {
    ZonedDateTime zonedDateTime = dateTime.atZone(ZoneOffset.UTC);

    byte[] bytes = new byte[5];
    bytes[0] = (byte) (zonedDateTime.getYear() - 2000);
    bytes[1] = (byte) (zonedDateTime.getMonthValue());
    bytes[2] = (byte) (zonedDateTime.getDayOfMonth());
    bytes[3] = (byte) (zonedDateTime.getHour());
    bytes[4] = (byte) (zonedDateTime.getMinute());

    return Hex.encodeHexString(bytes);
}
 
開發者ID:amvnetworks,項目名稱:amv-highmobility-cryptotool-wrapper,代碼行數:13,代碼來源:CryptotoolUtils.java

示例5: test_London_getStandardOffset

import java.time.ZonedDateTime; //導入方法依賴的package包/類
public void test_London_getStandardOffset() {
    ZoneRules test = europeLondon();
    ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC);
    while (zdt.getYear() < 2010) {
        Instant instant = zdt.toInstant();
        if (zdt.getYear() < 1848) {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -1, -15));
        } else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) {
            assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
        } else {
            assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
        }
        zdt = zdt.plusMonths(6);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:16,代碼來源:TCKZoneRules.java

示例6: test_NewYork_getStandardOffset

import java.time.ZonedDateTime; //導入方法依賴的package包/類
public void test_NewYork_getStandardOffset() {
    ZoneRules test = americaNewYork();
    ZonedDateTime dateTime = createZDT(1860, 1, 1, ZoneOffset.UTC);
    while (dateTime.getYear() < 2010) {
        Instant instant = dateTime.toInstant();
        if (dateTime.toLocalDate().isBefore(LocalDate.of(1883, 11, 18))) {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.of("-04:56:02"));
        } else {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHours(-5));
        }
        dateTime = dateTime.plusMonths(6);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:TCKZoneRules.java

示例7: isEqual

import java.time.ZonedDateTime; //導入方法依賴的package包/類
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
    ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
    return zdt.getYear() == ts.getYear() + 1900 &&
           zdt.getMonthValue() == ts.getMonth() + 1 &&
           zdt.getDayOfMonth() == ts.getDate() &&
           zdt.getHour() == ts.getHours() &&
           zdt.getMinute() == ts.getMinutes() &&
           zdt.getSecond() == ts.getSeconds() &&
           zdt.getNano() == ts.getNanos();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:11,代碼來源:JavatimeTest.java

示例8: convertDateIntoYears

import java.time.ZonedDateTime; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public static int convertDateIntoYears(String date) {
    String year = date.substring(0, 4);
    String month = date.substring(5, 7);
    String day = date.substring(8, 10);

    ZonedDateTime a = ZonedDateTime.now();
    Date newDate = new Date(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));
    Date newDate1 = new Date(a.getYear(), a.getMonthValue(), a.getDayOfMonth());

    long time = newDate1.getTime() - newDate.getTime();
    int years = (int) ((time / (1000 * 60 * 60 * 24)) / 31 / 12);
    return years;
}
 
開發者ID:xSzymo,項目名稱:Spring-web-shop-project,代碼行數:15,代碼來源:UserDAO.java

示例9: truncate

import java.time.ZonedDateTime; //導入方法依賴的package包/類
public static ZonedDateTime truncate(ZonedDateTime time, ChronoUnit unit,
                                     int stepRate, DayOfWeek firstDayOfWeek) {
    switch (unit) {
        case DAYS:
            return adjustField(time, DAY_OF_YEAR, stepRate).truncatedTo(unit);
        case HALF_DAYS:
            return time.truncatedTo(unit);
        case HOURS:
            return adjustField(time, HOUR_OF_DAY, stepRate).truncatedTo(unit);
        case MINUTES:
            return adjustField(time, MINUTE_OF_HOUR, stepRate)
                    .truncatedTo(unit);
        case SECONDS:
            return adjustField(time, SECOND_OF_MINUTE, stepRate).truncatedTo(
                    unit);
        case MILLIS:
            return adjustField(time, MILLI_OF_SECOND, stepRate).truncatedTo(
                    unit);
        case MICROS:
            return adjustField(time, MICRO_OF_SECOND, stepRate).truncatedTo(
                    unit);
        case NANOS:
            return adjustField(time, NANO_OF_SECOND, stepRate)
                    .truncatedTo(unit);
        case MONTHS:
            return time
                    .with(MONTH_OF_YEAR,
                            Math.max(
                                    1,
                                    time.get(MONTH_OF_YEAR)
                                            - time.get(MONTH_OF_YEAR)
                                            % stepRate)).withDayOfMonth(1)
                    .truncatedTo(DAYS);
        case YEARS:
            return adjustField(time, ChronoField.YEAR, stepRate).withDayOfYear(
                    1).truncatedTo(DAYS);
        case WEEKS:
            return time.with(DAY_OF_WEEK, firstDayOfWeek.getValue()).truncatedTo(
                    DAYS);
        case DECADES:
            int decade = time.getYear() / 10 * 10;
            return time.with(ChronoField.YEAR, decade).withDayOfYear(1)
                    .truncatedTo(DAYS);
        case CENTURIES:
            int century = time.getYear() / 100 * 100;
            return time.with(ChronoField.YEAR, century).withDayOfYear(1)
                    .truncatedTo(DAYS);
        case MILLENNIA:
            int millenium = time.getYear() / 1000 * 1000;
            return time.with(ChronoField.YEAR, millenium).withDayOfYear(1)
                    .truncatedTo(DAYS);
        default:
    }

    return time;
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:57,代碼來源:Util.java

示例10: zonedDateTimeToDateValue

import java.time.ZonedDateTime; //導入方法依賴的package包/類
static DateValue zonedDateTimeToDateValue(ZonedDateTime dt) {
    return new DateTimeValueImpl(
            dt.getYear(), dt.getMonthValue(), dt.getDayOfMonth(),
            dt.getHour(), dt.getMinute(), dt.getSecond());
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:6,代碼來源:ZonedDateTimeIteratorFactory.java


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