Class DateUtil


  • public final class DateUtil
    extends java.lang.Object
    This class provides date utils.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ISO_PATTERN_DATE  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long convertDaysInMiliseconds​(long lDays)
      Get the number of milliseconds in a given number of days
      static java.util.Date formatDate​(java.lang.String strDate, java.util.Locale locale)
      Get the date from String date The format pattern is specified internaly
      static java.util.Date formatDateLongYear​(java.lang.String strDate, java.util.Locale locale)
      Get the date from String date
      static java.sql.Date formatDateSql​(java.lang.String strDate, java.util.Locale locale)
      Get the Date from String date The format pattern is specified internaly
      static java.sql.Timestamp formatTimestamp​(java.lang.String strDate, java.util.Locale locale)
      Get the Timestamp from String date The format pattern is specified internaly
      static java.lang.String getCurrentDateString​(java.util.Locale locale)
      Converts the current Date to a String date
      static java.text.DateFormat getDateFormat​(java.util.Locale locale)
      Get the Date format for the locale
      static java.lang.String getDateString​(long lTime, java.util.Locale locale)
      Converts a long value to a String date
      static java.lang.String getDateString​(java.sql.Timestamp date, java.util.Locale locale)
      Converts a Timestamp value to a String date
      static java.lang.String getDateString​(java.util.Date date, java.util.Locale locale)
      Convert the date to String with a standard pattern
      static java.lang.String getDefaultPattern​(java.util.Locale locale)
      Return the pattern for date
      static java.lang.String getIsoDateString​(java.util.Date date)
      Get the ISO format ( yyyy-MM-dd HH:mm:ss ) of a date
      static java.util.Date parseIsoDate​(java.lang.String strDate)
      Parse a date from ISO format ( yyyy-MM-dd HH:mm:ss )
      • Methods inherited from class java.lang.Object

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

      • ISO_PATTERN_DATE

        public static final java.lang.String ISO_PATTERN_DATE
        See Also:
        Constant Field Values
    • Method Detail

      • formatDate

        public static java.util.Date formatDate​(java.lang.String strDate,
                                                java.util.Locale locale)
        Get the date from String date The format pattern is specified internaly
        Parameters:
        strDate - the date to format
        locale - The Locale
        Returns:
        The Date or null else
      • formatDateLongYear

        public static java.util.Date formatDateLongYear​(java.lang.String strDate,
                                                        java.util.Locale locale)
        Get the date from String date
        Parameters:
        strDate - the date to format
        locale - The Locale
        Returns:
        The Date or null else
      • formatTimestamp

        public static java.sql.Timestamp formatTimestamp​(java.lang.String strDate,
                                                         java.util.Locale locale)
        Get the Timestamp from String date The format pattern is specified internaly
        Parameters:
        strDate - the date to format
        locale - The Locale
        Returns:
        The Timestamp or null else
      • formatDateSql

        public static java.sql.Date formatDateSql​(java.lang.String strDate,
                                                  java.util.Locale locale)
        Get the Date from String date The format pattern is specified internaly
        Parameters:
        strDate - the date to format
        locale - The Locale
        Returns:
        The Date or null else
      • getDateString

        public static java.lang.String getDateString​(java.util.Date date,
                                                     java.util.Locale locale)
        Convert the date to String with a standard pattern
        Parameters:
        date - The date to convert
        locale - The Locale
        Returns:
        The formated String
      • getDateString

        public static java.lang.String getDateString​(long lTime,
                                                     java.util.Locale locale)
        Converts a long value to a String date
        Parameters:
        lTime - The long value to convert
        locale - the locale
        Returns:
        The formatted string
      • getDateString

        public static java.lang.String getDateString​(java.sql.Timestamp date,
                                                     java.util.Locale locale)
        Converts a Timestamp value to a String date
        Parameters:
        date - The date
        locale - the locale
        Returns:
        The formatted string
      • getCurrentDateString

        public static java.lang.String getCurrentDateString​(java.util.Locale locale)
        Converts the current Date to a String date
        Parameters:
        locale - the locale
        Returns:
        The formatted string
      • getDefaultPattern

        public static java.lang.String getDefaultPattern​(java.util.Locale locale)
        Return the pattern for date
        Parameters:
        locale - the Locale
        Returns:
        The pattern as a String
      • convertDaysInMiliseconds

        public static long convertDaysInMiliseconds​(long lDays)
        Get the number of milliseconds in a given number of days
        Parameters:
        lDays - The number of days
        Returns:
        The number of milliseconds in the given number of days
      • getDateFormat

        public static java.text.DateFormat getDateFormat​(java.util.Locale locale)
        Get the Date format for the locale
        Parameters:
        locale -
        Returns:
      • parseIsoDate

        public static java.util.Date parseIsoDate​(java.lang.String strDate)
        Parse a date from ISO format ( yyyy-MM-dd HH:mm:ss )
        Parameters:
        strDate -
        Returns:
        parsed Date or null if the string can't be parsed
        Since:
        7.0.1
      • getIsoDateString

        public static java.lang.String getIsoDateString​(java.util.Date date)
        Get the ISO format ( yyyy-MM-dd HH:mm:ss ) of a date
        Parameters:
        date -
        Returns:
        string of the date in iso format, or null if param is null
        Since:
        7.0.1