Class ThreadSafeDateFormatter


  • public class ThreadSafeDateFormatter
    extends java.lang.Object
    Class for formatting Date objects in a thread-safe manner.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String format​(java.text.DateFormat dateFormat, java.util.Date date)
      This class / method exists because DateFormats are notoriously not thread safe.
      static java.util.Date parse​(java.text.DateFormat dateFormat, java.lang.String dateString)
      This class / method exists because DateFormats are notoriously not thread safe.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ThreadSafeDateFormatter

        public ThreadSafeDateFormatter()
    • Method Detail

      • format

        public static java.lang.String format​(java.text.DateFormat dateFormat,
                                              java.util.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 java.util.Date parse​(java.text.DateFormat dateFormat,
                                           java.lang.String dateString)
                                    throws java.text.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:
        java.text.ParseException - if provided string is not parseable