Class ThreadSafeDateFormatter


  • public class ThreadSafeDateFormatter
    extends Object
    Class for formatting Date objects in a thread-safe manner.
    • Constructor Detail

      • ThreadSafeDateFormatter

        public ThreadSafeDateFormatter()
    • Method Detail

      • format

        public static String format​(DateFormat dateFormat,
                                    Date date)
        This class / method exists because DateFormats are notoriously not thread safe. This method ensures thread safety of formatting a date.
        Parameters:
        dateFormat - Date format to use
        date - Date to format
        Returns:
        Formatted date
      • parse

        public static Date parse​(DateFormat dateFormat,
                                 String dateString)
                          throws ParseException
        This class / method exists because DateFormats are notoriously not thread safe. This method ensures thread safety of parsing a date.
        Parameters:
        dateFormat - Date format to use
        dateString - String to parse
        Returns:
        Date parsed from string
        Throws:
        ParseException - if provided string is not parseable