本文整理了Java中java.time.format.DateTimeFormatter.getZone()
方法的一些代码示例,展示了DateTimeFormatter.getZone()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTimeFormatter.getZone()
方法的具体详情如下:
包路径:java.time.format.DateTimeFormatter
类名称:DateTimeFormatter
方法名:getZone
[英]Gets the overriding zone to be used during formatting.
This returns the override zone, used to convert instants. By default, a formatter has no override zone, returning null. See #withZone(ZoneId) for more details on overriding.
[中]获取格式化期间要使用的覆盖区域。
这将返回覆盖区域,用于转换实例。默认情况下,格式化程序没有覆盖区域,返回null。有关覆盖的详细信息,请参见#withZone(ZoneId)。
代码示例来源:origin: jooby-project/jooby
private static LocalDate parse(final DateTimeFormatter formatter, final String value) {
try {
Instant epoch = Instant.ofEpochMilli(Long.parseLong(value));
ZonedDateTime zonedDate = epoch.atZone(
Optional.ofNullable(formatter.getZone())
.orElse(ZoneId.systemDefault())
);
return zonedDate.toLocalDate();
} catch (NumberFormatException ex) {
return LocalDate.parse(value, formatter);
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public ZoneId zone() {
return this.printer.getZone();
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public boolean equals(Object obj) {
if (obj.getClass().equals(this.getClass()) == false) {
return false;
}
JavaDateFormatter other = (JavaDateFormatter) obj;
return Objects.equals(format, other.format) &&
Objects.equals(locale(), other.locale()) &&
Objects.equals(this.printer.getZone(), other.printer.getZone());
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public int hashCode() {
return Objects.hash(locale(), printer.getZone(), format);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public DateFormatter withZone(ZoneId zoneId) {
// shortcurt to not create new objects unnecessarily
if (zoneId.equals(parsers[0].getZone())) {
return this;
}
final DateTimeFormatter[] parsersWithZone = new DateTimeFormatter[parsers.length];
for (int i = 0; i < parsers.length; i++) {
parsersWithZone[i] = parsers[i].withZone(zoneId);
}
return new JavaDateFormatter(format, printer.withZone(zoneId), parsersWithZone);
}
代码示例来源:origin: apache/sis
/**
* Returns the timezone used for formatting instants.
*
* @return the timezone.
*/
@Override
public final TimeZone getTimeZone() {
final ZoneId zone = format.getZone();
return TimeZone.getTimeZone(zone != null ? zone : ZoneOffset.UTC);
}
代码示例来源:origin: org.jooby/jooby
private static LocalDate parse(final DateTimeFormatter formatter, final String value) {
try {
Instant epoch = Instant.ofEpochMilli(Long.parseLong(value));
ZonedDateTime zonedDate = epoch.atZone(
Optional.ofNullable(formatter.getZone())
.orElse(ZoneId.systemDefault())
);
return zonedDate.toLocalDate();
} catch (NumberFormatException ex) {
return LocalDate.parse(value, formatter);
}
}
代码示例来源:origin: apache/servicemix-bundles
@Override
public boolean equals(Object obj) {
if (obj.getClass().equals(this.getClass()) == false) {
return false;
}
JavaDateFormatter other = (JavaDateFormatter) obj;
return Objects.equals(format, other.format) &&
Objects.equals(getLocale(), other.getLocale()) &&
Objects.equals(this.printer.getZone(), other.printer.getZone());
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch
@Override
public int hashCode() {
return Objects.hash(getLocale(), printer.getZone(), format);
}
代码示例来源:origin: org.eclipse/yasson
/**
* Append UTC zone in case zone is not set on formatter.
*
* @param formatter formatter
* @return zoned formatter
*/
protected DateTimeFormatter getZonedFormatter(DateTimeFormatter formatter) {
return formatter.getZone() != null ?
formatter : formatter.withZone(UTC);
}
代码示例来源:origin: apache/servicemix-bundles
@Override
public int hashCode() {
return Objects.hash(getLocale(), printer.getZone(), format);
}
代码示例来源:origin: org.eclipse/yasson
/**
* Append UTC zone in case zone is not set on formatter.
*
* @param formatter formatter
* @return zoned formatter
*/
protected DateTimeFormatter getZonedFormatter(DateTimeFormatter formatter) {
return formatter.getZone() != null ?
formatter : formatter.withZone(UTC);
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
private static DateTimeFormatter withZone(DateTimeFormatter dateTimeFormatter, ZoneId zoneId) {
if (zoneId != null) {
return dateTimeFormatter.withZone(zoneId);
} else if (dateTimeFormatter.getZone() == null) {
return dateTimeFormatter.withZone(ZoneId.systemDefault());
}
return dateTimeFormatter;
}
代码示例来源:origin: horrorho/LiquidDonkey
public static BackupFormatter create(String indent, DateTimeFormatter dateTimeFormatter) {
if (dateTimeFormatter.getLocale() == null) {
dateTimeFormatter = dateTimeFormatter.withLocale(Locale.getDefault());
}
if (dateTimeFormatter.getZone() == null) {
dateTimeFormatter = dateTimeFormatter.withZone(ZoneId.systemDefault());
}
return new BackupFormatter(indent, dateTimeFormatter);
}
代码示例来源:origin: apache/servicemix-bundles
@Override
public DateFormatter withZone(ZoneId zoneId) {
// shortcurt to not create new objects unnecessarily
if (zoneId.equals(parsers[0].getZone())) {
return this;
}
final DateTimeFormatter[] parsersWithZone = new DateTimeFormatter[parsers.length];
for (int i = 0; i < parsers.length; i++) {
parsersWithZone[i] = parsers[i].withZone(zoneId);
}
return new JavaDateFormatter(format, printer.withZone(zoneId), parsersWithZone);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch
@Override
public DateFormatter withZone(ZoneId zoneId) {
// shortcurt to not create new objects unnecessarily
if (zoneId.equals(parsers[0].getZone())) {
return this;
}
final DateTimeFormatter[] parsersWithZone = new DateTimeFormatter[parsers.length];
for (int i = 0; i < parsers.length; i++) {
parsersWithZone[i] = parsers[i].withZone(zoneId);
}
return new JavaDateFormatter(format, printer.withZone(zoneId), parsersWithZone);
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
@Test
public void testFormattersFromFormatterWithOwnTZ() {
final DateTimeFormatter[] yyyyMMdd = JavaTimeHelper.getDateTimeFormatters(DATE_TIME_FORMATTER_WITH_TZ_SUPPLIER);
assertEquals(DateTimeFormatter.ofPattern("ddMMyyyy").toString(), yyyyMMdd[0].toString());
assertEquals(ZoneId.of("America/Chicago"), yyyyMMdd[0].getZone());
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
@Test
public void testFormattersFromString() {
final DateTimeFormatter[] yyyyMMdd = JavaTimeHelper.getDateTimeFormatters(new DateFormatSupplier() {
@Override
public String get() {
return "yyyyMMdd";
}
});
assertEquals(DateTimeFormatter.ofPattern("yyyyMMdd").toString(), yyyyMMdd[0].toString());
assertEquals(ZoneId.systemDefault(), yyyyMMdd[0].getZone());
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
@Test
public void testFormattersFromFormatter() {
final DateTimeFormatter[] yyyyMMdd = JavaTimeHelper.getDateTimeFormatters(DATE_TIME_FORMATTER_SUPPLIER);
assertEquals(DateTimeFormatter.ofPattern("MMddyyyy").toString(), yyyyMMdd[0].toString());
assertEquals(ZoneId.systemDefault(), yyyyMMdd[0].getZone());
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
@Test
public void testFormattersFromFormatterWithSpecifiedTZ() {
final DateTimeFormatter[] yyyyMMdd = JavaTimeHelper.getDateTimeFormatters(DATE_TIME_FORMATTER_WITH_TZ_SUPPLIER, TIME_ZONE_SUPPLIER);
assertEquals(DateTimeFormatter.ofPattern("ddMMyyyy").toString(), yyyyMMdd[0].toString());
assertEquals(ZoneId.of("America/New_York"), yyyyMMdd[0].getZone());
}
内容来源于网络,如有侵权,请联系作者删除!