当前位置: 首页>>代码示例>>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;未经允许,请勿转载。