java.time.format.DateTimeFormatter.ofLocalizedTime()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(203)

本文整理了Java中java.time.format.DateTimeFormatter.ofLocalizedTime()方法的一些代码示例,展示了DateTimeFormatter.ofLocalizedTime()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTimeFormatter.ofLocalizedTime()方法的具体详情如下:
包路径:java.time.format.DateTimeFormatter
类名称:DateTimeFormatter
方法名:ofLocalizedTime

DateTimeFormatter.ofLocalizedTime介绍

[英]Returns a locale specific time format.

This returns a formatter that will print/parse a 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

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: 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.ofLocalizedTime(this.timeStyle);

代码示例来源:origin: org.springframework/spring-context

dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(this.timeStyle);

代码示例来源:origin: com.haulmont.cuba/cuba-global

@Override
protected DateTimeFormatter getDateTimeFormatter() {
  return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

@Override
protected DateTimeFormatter getDateTimeFormatter() {
  return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
}

代码示例来源:origin: otto-de/edison-microservice

private String formatTime(final OffsetDateTime dateTime) {
  if (dateTime==null) {
    return null;
  } else {
    return humanReadable
        ? ofLocalizedTime(MEDIUM).format(dateTime)
        : ISO_OFFSET_DATE_TIME.format(dateTime);
  }
}

代码示例来源:origin: stackoverflow.com

import java.time.Duration;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;

public class TimeDiff {
  public static void main(String[] args) {
    DateTimeFormatter format = DateTimeFormatter
        .ofLocalizedTime(FormatStyle.SHORT);
    LocalTime time1 = LocalTime.parse("11:00 AM", format);
    LocalTime time2 = LocalTime.parse("01:00 PM", format);
    Duration duration = Duration.between(time1, time2);
    System.out.println(Math.abs(duration.getSeconds() / 3600));
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy-datetime

/**
 * Formats this time in the provided, localized {@link java.time.format.FormatStyle}.
 *
 * @param self      a LocalTime
 * @param timeStyle the FormatStyle
 * @return a formatted String
 * @see java.time.format.DateTimeFormatter
 * @since 2.5.0
 */
public static String format(final LocalTime self, FormatStyle timeStyle) {
  return self.format(DateTimeFormatter.ofLocalizedTime(timeStyle));
}

代码示例来源:origin: org.codehaus.groovy/groovy-datetime

/**
 * Formats this time in the provided, localized {@link java.time.format.FormatStyle}.
 *
 * @param self      an OffsetTime
 * @param timeStyle the FormatStyle
 * @return a formatted String
 * @see java.time.format.DateTimeFormatter
 * @since 2.5.0
 */
public static String format(final OffsetTime self, FormatStyle timeStyle) {
  return self.format(DateTimeFormatter.ofLocalizedTime(timeStyle));
}

代码示例来源:origin: apache/wicket

@Override
public DateTimeFormatter getDateTimeFormatter(Locale locale)
{
  return DateTimeFormatter.ofLocalizedTime(timeStyle).withLocale(locale);
}

代码示例来源:origin: com.github.lgooddatepicker/LGoodDatePicker

public static void main(String[] args) {
    TreeSet<String> languageCodes = new TreeSet<String>();
    for (Locale locale : Locale.getAvailableLocales()) {
      languageCodes.add(locale.getLanguage());

    }

    LocalTime localTime = LocalTime.of(17, 30, 20);

    for (String languageCode : languageCodes) {

      Locale localeForLanguage = new Locale(languageCode);
      // Locale localeForLanguage = Locale.forLanguageTag(languageCode);
      DateTimeFormatter format = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withLocale(localeForLanguage);
      System.out.print(localeForLanguage.getDisplayLanguage() + ": ");
      System.out.print(format.format(localTime) + "\n");
    }

  }
}

代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-models

@Override
protected String convertTime(final LocalTime time, final Attribute attribute, final ProductType productType) {
  final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withLocale(locale());
  return dateTimeFormatter.format(time);
}

代码示例来源:origin: io.sphere.sdk.jvm/sphere-models

@Override
protected String convertTime(final LocalTime time, final Attribute attribute, final ProductType productType) {
  final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withLocale(locale());
  return dateTimeFormatter.format(time);
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Override
protected String convertTime(final LocalTime time, final Attribute attribute, final ProductType productType) {
  final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withLocale(locale());
  return dateTimeFormatter.format(time);
}

代码示例来源:origin: com.holon-platform.vaadin/holon-vaadin-flow

private static char obtainTimeSeparator(Locale locale) {
  String value = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withLocale(locale)
      .format(LocalTime.of(0, 0));
  if (value != null) {
    char[] chars = value.toCharArray();
    for (int i = 0; i < chars.length; i++) {
      if (i > 3) {
        break;
      }
      if (!Character.isDigit(chars[i])) {
        return chars[i];
      }
    }
  }
  return DEFAULT_TIME_SEPARATOR;
}

代码示例来源:origin: apache/servicemix-bundles

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: nroduit/Weasis

public static DateTimeFormatter getTimeFormatter(FormatStyle style) {
  return DateTimeFormatter.ofLocalizedTime(style).withLocale(getLocaleFormat());
}

代码示例来源:origin: com.holon-platform.core/holon-core

/**
 * Present {@link Temporal} property value using default {@link Locale}
 * @param value Property value to present
 * @return Formatted value
 */
private static String convertTemporalWithDefaultLocale(Temporal value) {
  // use default formatters
  final TemporalType type = TemporalType.getTemporalType(value).orElse(TemporalType.DATE);
  switch (type) {
  case DATE_TIME:
    return DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(Locale.getDefault())
        .format(value);
  case TIME:
    return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withLocale(Locale.getDefault()).format(value);
  case DATE:
  default:
    return DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withLocale(Locale.getDefault()).format(value);
  }
}

代码示例来源:origin: langurmonkey/gaiasky

public DesktopDateFormat(Locale loc, boolean date, boolean time) {
  assert date || time : "Formatter must include date or time";
  if (date && !time) {
    df = DateTimeFormatter.ofPattern("MMM dd uuuu").withLocale(Locale.US).withZone(ZoneOffset.UTC);
  } else if (!date && time)
    df = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM).withLocale(Locale.US).withZone(ZoneOffset.UTC);
  else if (date && time)
    df = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.MEDIUM).withLocale(Locale.US).withZone(ZoneOffset.UTC);
}

相关文章