Class PDTFormatter

java.lang.Object
com.helger.commons.datetime.PDTFormatter

@Immutable public final class PDTFormatter extends Object
Create common DateTimeFormatter objects used for printing and parsing date and time objects.
Author:
Philip Helger
  • Field Details

    • DEFAULT_STYLE

      public static final FormatStyle DEFAULT_STYLE
      By default the medium style is used
  • Method Details

    • toFormatStyle

      @Nonnull public static FormatStyle toFormatStyle(int nStyle)
    • toDateStyle

      public static int toDateStyle(@Nonnull FormatStyle eStyle)
    • getPattern

      @Nonnull public static String getPattern(@Nonnull EDTType eDTType, @Nullable Locale aLocale, @Nonnull FormatStyle eStyle, @Nonnull EDTFormatterMode eMode)
    • getWithLocale

      @Nonnull public static DateTimeFormatter getWithLocale(@Nonnull DateTimeFormatter aFormatter, @Nullable Locale aDisplayLocale)
      Assign the passed display locale to the passed date time formatter.
      Parameters:
      aFormatter - The formatter to be modified. May not be null.
      aDisplayLocale - The display locale to be used. May be null.
      Returns:
      The modified date time formatter. Never null.
    • getFormatterDate

      @Nonnull public static DateTimeFormatter getFormatterDate(@Nonnull FormatStyle eStyle, @Nullable Locale aDisplayLocale, @Nonnull EDTFormatterMode eMode)
      Get the date formatter for the passed locale.
      Parameters:
      eStyle - The format style to be used. May not be null.
      aDisplayLocale - The display locale to be used. May be null.
      eMode - Print or parse? May not be null.
      Returns:
      The created date formatter. Never null.
      Since:
      8.5.6
    • getFormatterOffsetDate

      @Nonnull public static DateTimeFormatter getFormatterOffsetDate(@Nonnull FormatStyle eStyle, @Nullable Locale aDisplayLocale, @Nonnull EDTFormatterMode eMode)
      Get the date formatter for the passed locale.
      Parameters:
      eStyle - The format style to be used. May not be null.
      aDisplayLocale - The display locale to be used. May be null.
      eMode - Print or parse? May not be null.
      Returns:
      The created date formatter. Never null.
      Since:
      10.1.2
    • getFormatterTime

      @Nonnull public static DateTimeFormatter getFormatterTime(@Nonnull FormatStyle eStyle, @Nullable Locale aDisplayLocale, @Nonnull EDTFormatterMode eMode)
      Get the time formatter for the passed locale.
      Parameters:
      eStyle - The format style to be used. May not be null.
      aDisplayLocale - The display locale to be used. May be null.
      eMode - Print or parse? May not be null.
      Returns:
      The created time formatter. Never null.
      Since:
      8.5.6
    • getFormatterOffsetTime

      @Nonnull public static DateTimeFormatter getFormatterOffsetTime(@Nonnull FormatStyle eStyle, @Nullable Locale aDisplayLocale, @Nonnull EDTFormatterMode eMode)
      Get the time formatter for the passed locale.
      Parameters:
      eStyle - The format style to be used. May not be null.
      aDisplayLocale - The display locale to be used. May be null.
      eMode - Print or parse? May not be null.
      Returns:
      The created time formatter. Never null.
      Since:
      10.0.0
    • getFormatterDateTime

      @Nonnull public static DateTimeFormatter getFormatterDateTime(@Nonnull FormatStyle eStyle, @Nullable Locale aDisplayLocale, @Nonnull EDTFormatterMode eMode)
      Get the date time formatter for the passed locale.
      Parameters:
      eStyle - The format style to be used. May not be null.
      aDisplayLocale - The display locale to be used. May be null.
      eMode - Print or parse? May not be null.
      Returns:
      The created date time formatter. Never null.
      Since:
      8.5.6
    • getFormatterOffsetDateTime

      @Nonnull public static DateTimeFormatter getFormatterOffsetDateTime(@Nonnull FormatStyle eStyle, @Nullable Locale aDisplayLocale, @Nonnull EDTFormatterMode eMode)
      Get the date time formatter for the passed locale.
      Parameters:
      eStyle - The format style to be used. May not be null.
      aDisplayLocale - The display locale to be used. May be null.
      eMode - Print or parse? May not be null.
      Returns:
      The created date time formatter. Never null.
      Since:
      10.1.2
    • getFormatterZonedDateTime

      @Nonnull public static DateTimeFormatter getFormatterZonedDateTime(@Nonnull FormatStyle eStyle, @Nullable Locale aDisplayLocale, @Nonnull EDTFormatterMode eMode)
      Get the date time formatter for the passed locale.
      Parameters:
      eStyle - The format style to be used. May not be null.
      aDisplayLocale - The display locale to be used. May be null.
      eMode - Print or parse? May not be null.
      Returns:
      The created date time formatter. Never null.
      Since:
      10.1.2
    • getForPattern

      @Nonnull public static DateTimeFormatter getForPattern(@Nonnull String sPattern)
      Get the DateTimeFormatter for the given pattern, using our default chronology.
      Parameters:
      sPattern - The pattern to be parsed
      Returns:
      The formatter object.
      Throws:
      IllegalArgumentException - If the pattern is illegal
    • getForPattern

      @Nonnull public static DateTimeFormatter getForPattern(@Nonnull String sPattern, @Nullable Locale aDisplayLocale)
      Get the STRICT DateTimeFormatter for the given pattern and locale, using our default chronology.
      Parameters:
      sPattern - The pattern to be parsed
      aDisplayLocale - The locale to be used. May be null.
      Returns:
      The formatter object.
      Throws:
      IllegalArgumentException - If the pattern is illegal