本文整理匯總了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());
}
示例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;
}
示例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));
}
示例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);
}
示例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));
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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");
}
}
}
示例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);
}
}
示例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);
}
示例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));
}
示例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;
}
}
}
示例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)
);
}