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


Java ZoneId類代碼示例

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


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

示例1: test_NewYork_getOffsetInfo_overlap

import java.time.ZoneId; //導入依賴的package包/類
public void test_NewYork_getOffsetInfo_overlap() {
    ZoneId test = ZoneId.of("America/New_York");
    final LocalDateTime dateTime = LocalDateTime.of(2008, 11, 2, 1, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test.getRules(), dateTime, ZoneOffset.ofHours(-4), OVERLAP);
    assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(-4));
    assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(-5));
    assertEquals(trans.getInstant(), createInstant(2008, 11, 2, 2, 0, 0, 0, ZoneOffset.ofHours(-4)));
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-1)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-5)), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-4)), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(2)), false);
    assertEquals(trans.toString(), "Transition[Overlap at 2008-11-02T02:00-04:00 to -05:00]");

    assertFalse(trans.equals(null));
    assertFalse(trans.equals(ZoneOffset.ofHours(-4)));
    assertTrue(trans.equals(trans));

    final ZoneOffsetTransition otherTrans = test.getRules().getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));

    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:23,代碼來源:TestZoneId.java

示例2: parseTime

import java.time.ZoneId; //導入依賴的package包/類
private ZonedDateTime parseTime(String time) {
  // TODO : may support more than one format at some point
  DateTimeFormatter dtf =
      DateTimeFormatter.ofPattern(Schedule.DATETIME_FORMATS[0]).withZone(ZoneId.systemDefault());
  ZonedDateTime zdt = null;

  try {
    zdt = ZonedDateTime.parse(time, dtf);
  } catch (DateTimeParseException e) {
    logger.debug("parseTime() failed to parse '" + time + "'");
    // throw an exception
    // mark as complete (via max iterations?)
  }

  return zdt;
}
 
開發者ID:mgjeong,項目名稱:device-opcua-java,代碼行數:17,代碼來源:ScheduleContext.java

示例3: registerParsers

import java.time.ZoneId; //導入依賴的package包/類
/**
 * Registers the default parsers for these formats
 * NOTE THAT THE ORDER IN WHICH THESE ARE REGISTERED MATTERS SOMEWHAT (MORE SPECIFIC TO LESS SPECIFIC)
 */
private void registerParsers() {
    this.setParser(boolean.class, Parser.ofBoolean().withNullChecker(nullCheck));
    this.setParser(Boolean.class, Parser.ofBoolean().withNullChecker(nullCheck));
    this.setParser(int.class, Parser.ofInteger().withNullChecker(nullCheck));
    this.setParser(Integer.class, Parser.ofInteger().withNullChecker(nullCheck));
    this.setParser(long.class, Parser.ofLong().withNullChecker(nullCheck));
    this.setParser(Long.class, Parser.ofLong().withNullChecker(nullCheck));
    this.setParser(double.class, Parser.ofDouble("0.0000####;-0.0000####", 1).withNullChecker(nullCheck));
    this.setParser(Double.class, Parser.ofDouble("0.0000####;-0.0000####", 1).withNullChecker(nullCheck));
    this.setParser(BigDecimal.class, Parser.ofBigDecimal().withNullChecker(nullCheck));
    this.setParser(LocalDate.class, Parser.ofLocalDate(DateTimeFormatter.ISO_LOCAL_DATE).withNullChecker(nullCheck));
    this.setParser(LocalTime.class, Parser.ofLocalTime(DateTimeFormatter.ISO_LOCAL_TIME).withNullChecker(nullCheck));
    this.setParser(LocalDateTime.class, Parser.ofLocalDateTime(DateTimeFormatter.ISO_LOCAL_DATE_TIME).withNullChecker(nullCheck));
    this.setParser(ZonedDateTime.class, Parser.ofZonedDateTime(DateTimeFormatter.ISO_ZONED_DATE_TIME).withNullChecker(nullCheck));
    this.setParser(Period.class, Parser.ofPeriod().withNullChecker(nullCheck));
    this.setParser(ZoneId.class, Parser.ofZoneId().withNullChecker(nullCheck));
    this.setParser(Month.class, Parser.ofEnum(Month.class).withNullChecker(nullCheck));
    this.setParser(TimeZone.class, Parser.ofTimeZone().withNullChecker(nullCheck));
    this.setParser(java.util.Date.class, Parser.ofDate().withNullChecker(nullCheck));
    this.setParser(String.class, Parser.ofString().withNullChecker(nullCheck));
    this.setParser(Object.class, Parser.ofObject().withNullChecker(nullCheck));
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:27,代碼來源:Formats.java

示例4: testParseNullsWithSpecificCharacter

import java.time.ZoneId; //導入依賴的package包/類
@Test
public void testParseNullsWithSpecificCharacter() {
    final Formats formats = new Formats();
    formats.setNullValues("null", "-");
    assertEquals(formats.getParserOrFail(boolean.class).apply("-"), Boolean.FALSE);
    assertEquals(formats.getParserOrFail(boolean.class).apply("-"), Boolean.FALSE);
    assertEquals(formats.getParserOrFail(Boolean.class).apply("-"), Boolean.FALSE);
    assertEquals(formats.getParserOrFail(Boolean.class).apply("-"), Boolean.FALSE);
    assertEquals(formats.getParserOrFail(Integer.class).apply("-"), 0);
    assertEquals(formats.getParserOrFail(int.class).apply("-"), 0);
    assertEquals(formats.getParserOrFail(Long.class).apply("-"), 0L);
    assertEquals(formats.getParserOrFail(long.class).apply("-"), 0L);
    assertEquals(formats.getParserOrFail(Double.class).apply("-"), Double.NaN);
    assertEquals(formats.getParserOrFail(double.class).apply("-"), Double.NaN);
    assertEquals(formats.getParserOrFail(String.class).apply("-"), null);
    assertEquals(formats.getParserOrFail(ZoneId.class).apply("-"), null);
    assertEquals(formats.getParserOrFail(TimeZone.class).apply("-"), null);
    assertEquals(formats.getParserOrFail(LocalDate.class).apply("-"), null);
    assertEquals(formats.getParserOrFail(LocalDateTime.class).apply("-"), null);
    assertEquals(formats.getParserOrFail(ZonedDateTime.class).apply("-"), null);
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:22,代碼來源:FormatsTest.java

示例5: onFindAvailableRoomsButtonClicked

import java.time.ZoneId; //導入依賴的package包/類
/**
 * Searches the database for rooms that are available in the given date range.
 */
@FXML
private void onFindAvailableRoomsButtonClicked() {
    // The new date api is great. Converting back and forth, not so much.
    LocalDate checkInDateTemp = checkInDatePicker.getValue();
    LocalDate checkOutDateTemp = checkOutDatePicker.getValue();
    Instant temp1 = Instant.from(checkInDateTemp.atStartOfDay(ZoneId.systemDefault()));
    Instant temp2 = Instant.from(checkOutDateTemp.atStartOfDay(ZoneId.systemDefault()));
    Date checkInDate = Date.from(temp1);
    Date checkOutDate = Date.from(temp2);

    // Clear any existing results
    roomSearchResults.clear();
    selectedRooms.clear();

    // Get the new results
    BookingService bookingService = new BookingService();
    roomSearchResults.addAll(bookingService.getRoomTypesAvailable(checkInDate, checkOutDate));
}
 
開發者ID:maillouxc,項目名稱:git-rekt,代碼行數:22,代碼來源:BrowseRoomsScreenController.java

示例6: isRelevant

import java.time.ZoneId; //導入依賴的package包/類
protected boolean isRelevant(Entry<?> entry) {

        if (this instanceof LoadDataSettingsProvider) {
            C dateControl = getSkinnable();

            if (!(entry instanceof DraggedEntry) && !dateControl.isCalendarVisible(entry.getCalendar())) {
                return false;
            }

            LoadDataSettingsProvider provider = (LoadDataSettingsProvider) this;

            ZoneId zoneId = getSkinnable().getZoneId();
            LocalDate loadStartDate = provider.getLoadStartDate();
            LocalDate loadEndDate = provider.getLoadEndDate();

            return entry.isShowing(loadStartDate, loadEndDate, zoneId);
        }

        return false;
    }
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:21,代碼來源:DateControlSkin.java

示例7: validatePasswordCredentialAttributes

import java.time.ZoneId; //導入依賴的package包/類
public PasswordCredentialStatus validatePasswordCredentialAttributes(User user) {
    PasswordCredentialDao passwordCredentialDao = daoProvider.getDao(PasswordCredentialDao.class);
    PasswordCredential passwordCredential = passwordCredentialDao.selectById(user.getId());

    if (passwordCredential.isInitial()) {
        return INITIAL;
    }

    if (config.getPasswordPolicy().getExpires() != null) {
        Instant createdAt = passwordCredential.getCreatedAt().toInstant(ZoneId.systemDefault().getRules().getOffset(Instant.now()));
        return (createdAt.plus(config.getPasswordPolicy().getExpires()).isBefore(config.getClock().instant())) ?
                EXPIRED : VALID;
    }

    return VALID;
}
 
開發者ID:kawasima,項目名稱:bouncr,代碼行數:17,代碼來源:SignInService.java

示例8: testIsDateInNewRange

import java.time.ZoneId; //導入依賴的package包/類
@Test
public void testIsDateInNewRange() {
    LocalDateTime localDateTimeNow = LocalDateTime.now();
    long milliesNow = localDateTimeNow.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    boolean isDateInNewRange = DateConverter.getDefault().isDateInNewRange(milliesNow);
    assertTrue(isDateInNewRange);
    
    localDateTimeNow = LocalDateTime.now().minusDays(2).minusHours(23);
    milliesNow = localDateTimeNow.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    isDateInNewRange = DateConverter.getDefault().isDateInNewRange(milliesNow);
    assertTrue(isDateInNewRange);
    
    localDateTimeNow = LocalDateTime.now().minusDays(4);
    milliesNow = localDateTimeNow.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    isDateInNewRange = DateConverter.getDefault().isDateInNewRange(milliesNow);
    assertFalse(isDateInNewRange);
}
 
開發者ID:Naoghuman,項目名稱:ABC-List,代碼行數:18,代碼來源:DateConverterTest.java

示例9: evaluateMinOrMaxFunction

import java.time.ZoneId; //導入依賴的package包/類
private List<DataInstance> evaluateMinOrMaxFunction(List<DataInstance> dataInstances, UnaryExpression unaryExpression, boolean minFunction) {
    DataInstance found = null;
    long milliseconds = 0;
    for (DataInstance dataInstance : dataInstances) {
        Object value = evaluateExpressionItem(unaryExpression.getOperand(), dataInstance.valueListMap());
        if (value instanceof DvDateTime) {
            DvDateTime dvDateTime = (DvDateTime) value;
            long convertedDateTime = dvDateTime.getDateTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
            if (minFunction) {
                if (found == null || convertedDateTime < milliseconds) {
                    found = dataInstance;
                    milliseconds = convertedDateTime;
                }
            } else { // maxFunction
                if (found == null || convertedDateTime > milliseconds) {
                    found = dataInstance;
                    milliseconds = convertedDateTime;
                }
            }
        }
    }
    return found == null ? Collections.emptyList() : Collections.singletonList(found);
}
 
開發者ID:gdl-lang,項目名稱:gdl2,代碼行數:24,代碼來源:Interpreter.java

示例10: testSplitZonedDateTimes

import java.time.ZoneId; //導入依賴的package包/類
@Test(dataProvider = "directions")
public void testSplitZonedDateTimes(boolean ascending) {
    final Duration step = Duration.ofSeconds(1);
    final ZonedDateTime start = ZonedDateTime.of(2014, 1, 1, 14, 15, 20, 0, ZoneId.systemDefault());
    final ZonedDateTime end = start.plusSeconds(10000000 * (ascending ? 1 : -1));
    final Range<ZonedDateTime> range = Range.of(start, end, step);
    final List<Range<ZonedDateTime>> segments = range.split();
    Assert.assertTrue(segments.size() > 1, "There are multiple segments");
    for (int i=1; i<segments.size(); ++i) {
        final Range<ZonedDateTime> prior = segments.get(i-1);
        final Range<ZonedDateTime> next = segments.get(i);
        Assert.assertEquals(prior.end(), next.start(), "Date connect as expect");
        if (i == 1) Assert.assertEquals(prior.start(), range.start(), "First segment start matches range start");
        if (i == segments.size()-1) {
            Assert.assertEquals(next.end(), range.end(), "Last segment end matches range end");
        }
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:19,代碼來源:RangeSplitTests.java

示例11: test_parseSuccess_prefix

import java.time.ZoneId; //導入依賴的package包/類
@Test(dataProvider="parseSuccess")
public void test_parseSuccess_prefix(String text, int expectedIndex, int expectedErrorIndex, ZoneId expected) {
    builder.appendZoneId();
    pos.setIndex(3);
    String prefixText = "XXX" + text;
    TemporalAccessor parsed = builder.toFormatter().parseUnresolved(prefixText, pos);
    assertEquals(pos.getErrorIndex(), expectedErrorIndex >= 0  ? expectedErrorIndex + 3 : expectedErrorIndex, "Incorrect error index parsing: " + prefixText);
    assertEquals(pos.getIndex(), expectedIndex + 3, "Incorrect index parsing: " + prefixText);
    if (expected != null) {
        assertEquals(parsed.query(TemporalQueries.zoneId()), expected, "Incorrect zoneId parsing: " + prefixText);
        assertEquals(parsed.query(TemporalQueries.offset()), null, "Incorrect offset parsing: " + prefixText);
        assertEquals(parsed.query(TemporalQueries.zone()), expected, "Incorrect zone parsing: " + prefixText);
    } else {
        assertEquals(parsed, null);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:TCKZoneIdPrinterParser.java

示例12: buildDateHeader

import java.time.ZoneId; //導入依賴的package包/類
private void buildDateHeader(final StringBuilder builder) {

        ZonedDateTime dateTime;

        if (this.dateTime != null) {
            dateTime = this.dateTime;
        } else {
            dateTime = ZonedDateTime.now(ZoneId.of("GMT"));
        }

        builder.append(Constants.HEADER_DATE_PREFIX);
        builder.append(Constants.SPACE);
        builder.append(DateTimeFormatter.RFC_1123_DATE_TIME.format(dateTime));
        builder.append(Constants.NEW_LINE);

    }
 
開發者ID:galop-proxy,項目名稱:galop,代碼行數:17,代碼來源:ResponseBuilder.java

示例13: build_withDateTimeAndWithoutContent_returnsResponseWithDefaultContent

import java.time.ZoneId; //導入依賴的package包/類
@Test
public void build_withDateTimeAndWithoutContent_returnsResponseWithDefaultContent() {

    final ZonedDateTime dateTime = ZonedDateTime.of(2017, 3, 20, 19, 9, 3, 40, ZoneId.of("GMT"));
    final ResponseBuilder httpResponse = ResponseBuilder
            .createWithStatus(StatusCode.BAD_REQUEST)
            .dateTime(dateTime);

    final Charset expectedCharset = Charset.forName("UTF-8");
    final String expectedDefaultContent = StatusCode.BAD_REQUEST.getReason();
    final byte[] expectedDefaultContentBytes = expectedDefaultContent.getBytes(expectedCharset);
    final String expectedHttpResponse = "HTTP/1.1 400 Bad Request\r\n"
            + "date: Mon, 20 Mar 2017 19:09:03 GMT\r\n"
            + "content-length: " + expectedDefaultContentBytes.length + "\r\n"
            + "content-type: text/plain; charset=UTF-8\r\n"
            + "\r\n"
            + expectedDefaultContent;
    assertEquals(expectedHttpResponse, new String(httpResponse.build(), expectedCharset));

}
 
開發者ID:galop-proxy,項目名稱:galop,代碼行數:21,代碼來源:ResponseBuilderTest.java

示例14: isEqualTo

import java.time.ZoneId; //導入依賴的package包/類
@Override
public final boolean isEqualTo(int index, ZonedDateTime value) {
    if (value == null) {
        return values[index] == nullValue;
    } else {
        final long epochMills = value.toInstant().toEpochMilli();
        if (epochMills != values[index]) {
            return false;
        } else {
            final ZoneId zoneId = value.getZone();
            final short code1 = zoneIdMap1.get(zoneId);
            final short code2 = zoneIds[index];
            return code1 == code2;
        }
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:17,代碼來源:DenseArrayOfZonedDateTimes.java

示例15: DateAsText

import java.time.ZoneId; //導入依賴的package包/類
/**
 * Formats the milliseconds as date using the format and the locale.
 * @param milliseconds Milliseconds to format as date.
 * @param format The format to use.
 * @param locale The locale to use for the format.
 */
public DateAsText(final long milliseconds, final String format,
    final Locale locale) {
    this(
        ZonedDateTime.ofInstant(
            Instant.ofEpochMilli(milliseconds), ZoneId.of("UTC")
        ),
        DateTimeFormatter.ofPattern(format, locale)
    );
}
 
開發者ID:yegor256,項目名稱:cactoos,代碼行數:16,代碼來源:DateAsText.java


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