Class FormatUtil


  • public final class FormatUtil
    extends Object
    Utility methods related to formatting. Date formatting from string uses the US English locale when the locale is not specified. In addition to standard Java date format syntax, you can use the string "EPOCH" (or null) to represent an EPOCH format.
    Since:
    2.2.0
    Author:
    Pascal Essiembre
    • Method Detail

      • formatDateString

        public static String formatDateString​(String dateString,
                                              String fromFormat,
                                              String toFormat)
        Formats a string representation of a date, into another string date format.
        Parameters:
        dateString - the date to format
        fromFormat - source format (null means EPOCH)
        toFormat - target format (null means EPOCH)
        Returns:
        formatted date string, or null if unable to format
      • formatDateString

        public static String formatDateString​(String dateString,
                                              String fromFormat,
                                              String toFormat,
                                              String fieldName)
        Formats a string representation of a date, into another string date format.
        Parameters:
        dateString - the date to format
        fromFormat - source format
        toFormat - target format
        fieldName - optional field name for referencing in error messages
        Returns:
        formatted date string
      • formatDateString

        public static String formatDateString​(String dateString,
                                              String fromFormat,
                                              Locale fromLocale,
                                              String toFormat,
                                              Locale toLocale,
                                              String subjectName)
        Formats a string representation of a date, into another string date format.
        Parameters:
        dateString - the date to format
        fromFormat - source format
        fromLocale - source format locale
        toFormat - target format
        toLocale - target format locale
        subjectName - optional subject name to appear in error messages
        Returns:
        formatted date string
        Since:
        2.5.2
      • parseZonedDateTimeString

        public static ZonedDateTime parseZonedDateTimeString​(String dateString,
                                                             String fromFormat,
                                                             Locale fromLocale,
                                                             String subjectName,
                                                             ZoneId zoneId)
        Formats a string representation of a date, into another string date format.
        Parameters:
        dateString - the date to format
        fromFormat - source format
        fromLocale - source format locale
        subjectName - optional subject name to appear in error messages
        zoneId - time zone id or null to use system default or detected one if specified in format
        Returns:
        a local date time or null if date string is null or could not parse.
        Since:
        3.0.0