Package com.helger.commons.datetime
Class PDTFormatter
- java.lang.Object
-
- com.helger.commons.datetime.PDTFormatter
-
@Immutable public final class PDTFormatter extends Object
Create commonDateTimeFormatterobjects used for printing and parsing date and time objects.- Author:
- Philip Helger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPDTFormatter.CacheKeyInternal cache key forPDTFormatter.LocalizedDateFormatCache.static classPDTFormatter.LocalizedDateFormatCacheThis class caches the compiled patterns for localized date and time formatter.
-
Field Summary
Fields Modifier and Type Field Description static FormatStyleDEFAULT_STYLEBy default the medium style is used
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DateTimeFormattergetFormatterDate(FormatStyle eStyle, Locale aDisplayLocale, EDTFormatterMode eMode)Get the date formatter for the passed locale.static DateTimeFormattergetFormatterDateTime(FormatStyle eStyle, Locale aDisplayLocale, EDTFormatterMode eMode)Get the date time formatter for the passed locale.static DateTimeFormattergetFormatterOffsetDate(FormatStyle eStyle, Locale aDisplayLocale, EDTFormatterMode eMode)Get the date formatter for the passed locale.static DateTimeFormattergetFormatterOffsetDateTime(FormatStyle eStyle, Locale aDisplayLocale, EDTFormatterMode eMode)Get the date time formatter for the passed locale.static DateTimeFormattergetFormatterOffsetTime(FormatStyle eStyle, Locale aDisplayLocale, EDTFormatterMode eMode)Get the time formatter for the passed locale.static DateTimeFormattergetFormatterTime(FormatStyle eStyle, Locale aDisplayLocale, EDTFormatterMode eMode)Get the time formatter for the passed locale.static DateTimeFormattergetFormatterZonedDateTime(FormatStyle eStyle, Locale aDisplayLocale, EDTFormatterMode eMode)Get the date time formatter for the passed locale.static DateTimeFormattergetForPattern(String sPattern)Get theDateTimeFormatterfor the given pattern, using our default chronology.static DateTimeFormattergetForPattern(String sPattern, Locale aDisplayLocale)Get the STRICTDateTimeFormatterfor the given pattern and locale, using our default chronology.static StringgetPattern(EDTType eDTType, Locale aLocale, FormatStyle eStyle, EDTFormatterMode eMode)static DateTimeFormattergetWithLocale(DateTimeFormatter aFormatter, Locale aDisplayLocale)Assign the passed display locale to the passed date time formatter.static inttoDateStyle(FormatStyle eStyle)static FormatStyletoFormatStyle(int nStyle)
-
-
-
Field Detail
-
DEFAULT_STYLE
public static final FormatStyle DEFAULT_STYLE
By default the medium style is used
-
-
Method Detail
-
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 benull.aDisplayLocale- The display locale to be used. May benull.- 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 benull.aDisplayLocale- The display locale to be used. May benull.eMode- Print or parse? May not benull.- 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 benull.aDisplayLocale- The display locale to be used. May benull.eMode- Print or parse? May not benull.- 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 benull.aDisplayLocale- The display locale to be used. May benull.eMode- Print or parse? May not benull.- 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 benull.aDisplayLocale- The display locale to be used. May benull.eMode- Print or parse? May not benull.- 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 benull.aDisplayLocale- The display locale to be used. May benull.eMode- Print or parse? May not benull.- 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 benull.aDisplayLocale- The display locale to be used. May benull.eMode- Print or parse? May not benull.- 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 benull.aDisplayLocale- The display locale to be used. May benull.eMode- Print or parse? May not benull.- Returns:
- The created date time formatter. Never
null. - Since:
- 10.1.2
-
getForPattern
@Nonnull public static DateTimeFormatter getForPattern(@Nonnull String sPattern)
Get theDateTimeFormatterfor 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 STRICTDateTimeFormatterfor the given pattern and locale, using our default chronology.- Parameters:
sPattern- The pattern to be parsedaDisplayLocale- The locale to be used. May benull.- Returns:
- The formatter object.
- Throws:
IllegalArgumentException- If the pattern is illegal
-
-