本文整理了Java中java.time.format.DateTimeFormatter.ofLocalizedDateTime()
方法的一些代码示例,展示了DateTimeFormatter.ofLocalizedDateTime()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTimeFormatter.ofLocalizedDateTime()
方法的具体详情如下:
包路径:java.time.format.DateTimeFormatter
类名称:DateTimeFormatter
方法名:ofLocalizedDateTime
[英]Returns a locale specific date-time format, which is typically of short length.
This returns a formatter that will print/parse a date-time. The exact format pattern used varies by locale.
The locale is determined from the formatter. The formatter returned directly by this method will use the Locale#getDefault(). The locale can be controlled using DateTimeFormatter#withLocale(Locale)on the result of this method.
Note that the localized pattern is looked up lazily. This DateTimeFormatter holds the style required and the locale, looking up the pattern required on demand.
[中]返回特定于区域设置的日期时间格式,该格式通常长度较短。
这将返回一个格式化程序,该格式化程序将打印/解析日期时间。使用的确切格式模式因区域设置而异。
区域设置由格式化程序确定。此方法直接返回的格式化程序将使用区域设置#getDefault()。可以在此方法的结果上使用DateTimeFormatter#withLocale(locale)控制区域设置。
请注意,本地化模式是惰性地查找的。此DateTimeFormatter保存所需的样式和区域设置,根据需要查找所需的模式。
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new {@code DateTimeFormatter} using this factory.
* <p>If no specific pattern or style has been defined,
* {@link FormatStyle#MEDIUM medium date time format} will be used.
* @return a new date time formatter
* @see #createDateTimeFormatter(DateTimeFormatter)
*/
public DateTimeFormatter createDateTimeFormatter() {
return createDateTimeFormatter(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM));
}
代码示例来源:origin: org.springframework/spring-context
/**
* Create a new {@code DateTimeFormatter} using this factory.
* <p>If no specific pattern or style has been defined,
* {@link FormatStyle#MEDIUM medium date time format} will be used.
* @return a new date time formatter
* @see #createDateTimeFormatter(DateTimeFormatter)
*/
public DateTimeFormatter createDateTimeFormatter() {
return createDateTimeFormatter(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM));
}
代码示例来源:origin: spring-projects/spring-framework
private DateTimeFormatter getFallbackFormatter(Type type) {
switch (type) {
case DATE: return DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
case TIME: return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
default: return DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT);
}
}
代码示例来源:origin: kiegroup/optaplanner
public String getStartingTimestampAsMediumString() {
return startingTimestamp == null ? null : startingTimestamp.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM));
}
代码示例来源:origin: org.springframework/spring-context
private DateTimeFormatter getFallbackFormatter(Type type) {
switch (type) {
case DATE: return DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
case TIME: return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
default: return DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT);
}
}
代码示例来源:origin: spring-projects/spring-framework
dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(this.dateStyle, this.timeStyle);
代码示例来源:origin: spring-projects/spring-framework
@Test
public void createDateTimeFormatterWithFallback() {
DateTimeFormatter fallback = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG);
DateTimeFormatter formatter = factory.createDateTimeFormatter(fallback);
assertThat(formatter, is(sameInstance(fallback)));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void createDateTimeFormatter() {
assertThat(factory.createDateTimeFormatter().toString(), is(equalTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString())));
}
代码示例来源:origin: org.springframework/spring-context
dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(this.dateStyle, this.timeStyle);
代码示例来源:origin: spring-projects/spring-framework
@Test
public void getObject() {
factory.afterPropertiesSet();
assertThat(factory.getObject().toString(), is(equalTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString())));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void getObjectIsAlwaysSingleton() {
factory.afterPropertiesSet();
DateTimeFormatter formatter = factory.getObject();
assertThat(formatter.toString(), is(equalTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString())));
factory.setStylePattern("LL");
assertThat(factory.getObject(), is(sameInstance(formatter)));
}
代码示例来源:origin: com.vaadin/vaadin-server
/**
* Creates a new LocalDateTimeRenderer.
* <p>
* The renderer is configured to render with the grid's locale it is
* attached to, with the format style being {@code FormatStyle.LONG} for the
* date and {@code FormatStyle.SHORT} for time, with an empty string as its
* null representation.
*
* @see <a href=
* "https://docs.oracle.com/javase/8/docs/api/java/time/format/FormatStyle.html#LONG">
* FormatStyle.LONG</a>
* @see <a href=
* "https://docs.oracle.com/javase/8/docs/api/java/time/format/FormatStyle.html#SHORT">
* FormatStyle.SHORT</a>
*/
public LocalDateTimeRenderer() {
this(() -> DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG,
FormatStyle.SHORT), "");
getLocaleFromGrid = true;
}
代码示例来源:origin: com.vaadin/vaadin-server
@Override
protected String formatDate(LocalDateTime value) {
if (value == null) {
return "";
}
DateTimeFormatter dateTimeFormatter = DateTimeFormatter
.ofLocalizedDateTime(FormatStyle.SHORT);
Locale locale = getLocale();
if (locale != null) {
dateTimeFormatter = dateTimeFormatter.withLocale(locale);
}
return value.format(dateTimeFormatter);
}
代码示例来源:origin: org.codehaus.groovy/groovy-datetime
/**
* Formats this date/time in the provided, localized {@link java.time.format.FormatStyle}.
*
* @param self a LocalDateTime
* @param dateTimeStyle the FormatStyle
* @return a formatted String
* @see java.time.format.DateTimeFormatter
* @since 2.5.0
*/
public static String format(final LocalDateTime self, FormatStyle dateTimeStyle) {
return self.format(DateTimeFormatter.ofLocalizedDateTime(dateTimeStyle));
}
代码示例来源:origin: org.codehaus.groovy/groovy-datetime
/**
* Formats this date/time in the provided, localized {@link java.time.format.FormatStyle}.
*
* @param self a ZonedDateTime
* @param dateTimeStyle the FormatStyle
* @return a formatted String
* @see java.time.format.DateTimeFormatter
* @since 2.5.0
*/
public static String format(final ZonedDateTime self, FormatStyle dateTimeStyle) {
return self.format(DateTimeFormatter.ofLocalizedDateTime(dateTimeStyle));
}
代码示例来源:origin: org.codehaus.groovy/groovy-datetime
/**
* Formats this date/time in the provided, localized {@link java.time.format.FormatStyle}.
*
* @param self an OffsetDateTime
* @param dateTimeStyle the FormatStyle
* @return a formatted String
* @see java.time.format.DateTimeFormatter
* @since 2.5.0
*/
public static String format(final OffsetDateTime self, FormatStyle dateTimeStyle) {
return self.format(DateTimeFormatter.ofLocalizedDateTime(dateTimeStyle));
}
代码示例来源:origin: apache/wicket
@Override
public DateTimeFormatter getDateTimeFormatter(Locale locale)
{
return DateTimeFormatter.ofLocalizedDateTime(dateStyle, timeStyle).withLocale(locale);
}
代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-models
@Override
protected String convertDateTime(final ZonedDateTime dateTimeValue, final Attribute attribute, final ProductType productType) {
final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(locale());
return dateTimeFormatter.format(dateTimeValue);
}
代码示例来源:origin: com.liferay/com.liferay.dynamic.data.mapping.io
protected DateTimeFormatter getDateTimeFormatter() {
DateTimeFormatter dateTimeFormatter =
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT);
return dateTimeFormatter.withLocale(getLocale());
}
代码示例来源:origin: HubSpot/jinjava
private static DateTimeFormatter getFormatter(JinjavaInterpreter interpreter, FormattedDate d) {
if (!StringUtils.isBlank(d.getFormat())) {
try {
return StrftimeFormatter.formatter(d.getFormat(), interpreter.getConfig().getLocale());
} catch (IllegalArgumentException e) {
interpreter.addError(new TemplateError(ErrorType.WARNING, ErrorReason.SYNTAX_ERROR, ErrorItem.OTHER, e.getMessage(), null, interpreter.getLineNumber(), -1, null,
BasicTemplateErrorCategory.UNKNOWN_DATE, ImmutableMap.of("date", d.getDate().toString(), "exception", e.getMessage(), "lineNumber", String.valueOf(interpreter.getLineNumber()))));
}
}
return DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM);
}
内容来源于网络,如有侵权,请联系作者删除!