Class UtilsDate


  • public class UtilsDate
    extends java.lang.Object

    Class that provides methods for managing dates.

    Project:

    Library for the integration with the services of @Firma, eVisor and TS@.

    Version:
    1.0, 10/10/2020.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String FORMAT_DATE
      Constant attribute that represents the date format yyyy-MM-dd.
      static java.lang.String FORMAT_DATE_ADDITIONAL
      Constant attribute that represents the date format "yyyy/MM/dd EEE hh:mm:ss zzzz".
      static java.lang.String FORMAT_DATE_DOWN
      Constant attribute that represents the date format dd_MM_yyyy.
      static java.lang.String FORMAT_DATE_INVERTED
      Constant attribute that represents the date format "dd-MM-yyyy".
      static java.lang.String FORMAT_DATE_SLASH
      Constant attribute that represents the date format "dd/MM/yyyy/HH/mm/ss".
      static java.lang.String FORMAT_DATE_SMALL
      Constant attribute that represents the date format dd/MM/yyyy.
      static java.lang.String FORMAT_DATE_TIME
      Constant attribute that represents the date format yyyy-MM-dd HH:mm:ss.
      static java.lang.String FORMAT_DATE_TIME_ADDITIONAL
      Constant attribute that represents the date format "yyyy-MM-dd'T'HHmmssZ".
      static java.lang.String FORMAT_DATE_TIME_CRL_ISSUE_TIME
      Constant attribute that represents the date format "yyyy-MM-dd'T'HH:mm:ss".
      static java.lang.String FORMAT_DATE_TIME_FULL
      Constant attribute that represents the date format "yyyy-MM-dd HH:mm:ss,SSS".
      static java.lang.String FORMAT_DATE_TIME_JSON
      Constant attribute that represents the date format "yyyy-MM-dd'T'HH:mm:ss.SSSXXX".
      static java.lang.String FORMAT_DATE_TIME_JUNTA
      Constant attribute that represents the date format yyyyMMddHHmmss.
      static java.lang.String FORMAT_DATE_TIME_JUNTA_ADDITIONAL
      Constant attribute that represents the date format "yyyyMMddHHmmss.SZ".
      static java.lang.String FORMAT_DATE_TIME_MINUTES
      Constant attribute that represents the date format "dd-MMM-yyyy HH:mm".
      static java.lang.String FORMAT_DATE_TIME_MYSQL_HSQLDB
      Constant attribute that represents the date format "YYYY/MM/DD HH24:MI:SS".
      static java.lang.String FORMAT_DATE_TIME_NOTFULL
      Constant attribute that represents the date format "yyyy-MM-dd HH:mm:ss ZZZZ".
      static java.lang.String FORMAT_DATE_TIME_ORACLE
      Constant attribute that represents the date format "MM/DD/YYYY HH24:MI:SS".
      static java.lang.String FORMAT_DATE_TIME_SECONDS
      Constant attribute that represents the date format "dd-MM-yy_HH-mm-ss".
      static java.lang.String FORMAT_DATE_TIME_STANDARD
      Constant attribute that represents the date format "dd/MM/yyyy HH:mm:ss".
      static java.lang.String FORMAT_DATE_TIME_STANDARD_ADDITIONAL
      Constant attribute that represents the date format "dd/MM/yyyy HH:mm:ss.SSS".
      static java.lang.String FORMAT_DATE_TIME_TIMESTAMP
      Constant attribute that represents the date format "yyyy-MM-dd'T'HH:mm:ss'.'
      static java.lang.String FORMAT_DATE_TIME_TSL
      Constant attribute that represents the date format "yyyy-MM-dd'T'HH:mm:ss'Z".
      static java.lang.String FORMAT_DATE_TIME_UTC
      Constant attribute that represents the date format "yyyy-MM-dd'T'HH:mm:ss.SSS".
      static java.lang.String FORMAT_DATE_TIME_XML_CONFIGURATION
      Constant attribute that represents the date format "yyyy-MM-dd HH:mm:ss.SSS zzz".
      static java.lang.String FORMAT_FULL
      Constant attribute that represents the date format yyyy-MM-dd EEE HH:mm:ss ZZZZ.
      static java.lang.String FORMAT_TIME
      Constant attribute that represents the date format HH:mm:ss.
    • Constructor Summary

      Constructors 
      Constructor Description
      UtilsDate()
      Constructor method for the class UtilsDate.java.
      UtilsDate​(java.lang.String timezone)
      Constructor method for the class UtilsDate.java.
      UtilsDate​(java.lang.String dateString, java.lang.String dateFormat)
      Constructor method for the class UtilsDate.java.
      UtilsDate​(java.util.Calendar c)
      Constructor method for the class UtilsDate.java.
      UtilsDate​(java.util.Date pFecha)
      Constructor method for the class UtilsDate.java.
      UtilsDate​(java.util.TimeZone t)
      Constructor method for the class UtilsDate.java.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addDays​(int numDays)
      Method that adds a number of days to the date.
      java.lang.String addDaysToSystemDate​(int numDays)
      Method that adds a number of days to the system date.
      java.util.Date getDate()
      Gets the value of the attribute date.
      static java.util.Date getDateAddingDays​(java.util.Date initialDate, int numDays)
      Method that adds a number of days to certain date.
      static java.lang.Integer[] getHoursSecondsMinutes​(java.lang.Long milliseconds)
      Method that obtains the value in hours, minutes and seconds of a period in milliseconds.
      static java.lang.Long getPeriod​(java.lang.Long hourPeriod, java.lang.Long minutePeriod, java.lang.Long secondPeriod)
      Method that obtains a period in milliseconds.
      static java.lang.String getSystemDate​(java.lang.String formato)
      Method that obtains the current date and time of the system.
      static java.lang.String getSystemDateAddingDays​(java.lang.String initialDate, int numDays)
      Method that adds a number of days to certain date.
      static java.util.Date getUTCDate​(java.lang.String utcDate)
      Method that obtains a date from a string with UTC format.
      static java.lang.String modifyFormat​(java.lang.String initialDate, java.lang.String originalFormat, java.lang.String newFormat)
      Method that modifies the format of a date.
      static java.util.Date parseToPDFDate​(java.lang.String value)
      Method that returns a Date from a string representing a PDF Date conform to the ASN.1 date format.
      void setDate​(java.util.Date pFecha)
      Sets the value of the attribute date.
      java.lang.String toString()
      java.lang.String toString​(java.lang.String dateFormat)
      Method that obtains a string with the value of the date for certain format.
      static java.lang.String toString​(java.lang.String dateFormat, java.util.Date dateParam)
      Method that obtains a string with the value of the date for certain format.
      java.lang.String toString​(java.text.SimpleDateFormat simpleDateFormat)
      Method that obtains a string with the value of the date for certain format.
      java.lang.String toUTCString()
      Method that obtains a string which represents the date on UTC format.
      static java.util.Date transformDate​(java.lang.String initialDate, java.lang.String pattern)
      Method that obtains a date from a string using a determined pattern.
      • Methods inherited from class java.lang.Object

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

      • FORMAT_FULL

        public static final java.lang.String FORMAT_FULL
        Constant attribute that represents the date format yyyy-MM-dd EEE HH:mm:ss ZZZZ.
        See Also:
        Constant Field Values
      • FORMAT_DATE

        public static final java.lang.String FORMAT_DATE
        Constant attribute that represents the date format yyyy-MM-dd.
        See Also:
        Constant Field Values
      • FORMAT_TIME

        public static final java.lang.String FORMAT_TIME
        Constant attribute that represents the date format HH:mm:ss.
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME

        public static final java.lang.String FORMAT_DATE_TIME
        Constant attribute that represents the date format yyyy-MM-dd HH:mm:ss.
        See Also:
        Constant Field Values
      • FORMAT_DATE_SMALL

        public static final java.lang.String FORMAT_DATE_SMALL
        Constant attribute that represents the date format dd/MM/yyyy.
        See Also:
        Constant Field Values
      • FORMAT_DATE_DOWN

        public static final java.lang.String FORMAT_DATE_DOWN
        Constant attribute that represents the date format dd_MM_yyyy.
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_STANDARD

        public static final java.lang.String FORMAT_DATE_TIME_STANDARD
        Constant attribute that represents the date format "dd/MM/yyyy HH:mm:ss".
        See Also:
        Constant Field Values
      • FORMAT_DATE_SLASH

        public static final java.lang.String FORMAT_DATE_SLASH
        Constant attribute that represents the date format "dd/MM/yyyy/HH/mm/ss".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_JUNTA

        public static final java.lang.String FORMAT_DATE_TIME_JUNTA
        Constant attribute that represents the date format yyyyMMddHHmmss.
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_JUNTA_ADDITIONAL

        public static final java.lang.String FORMAT_DATE_TIME_JUNTA_ADDITIONAL
        Constant attribute that represents the date format "yyyyMMddHHmmss.SZ".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_ADDITIONAL

        public static final java.lang.String FORMAT_DATE_TIME_ADDITIONAL
        Constant attribute that represents the date format "yyyy-MM-dd'T'HHmmssZ".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_FULL

        public static final java.lang.String FORMAT_DATE_TIME_FULL
        Constant attribute that represents the date format "yyyy-MM-dd HH:mm:ss,SSS".
        See Also:
        Constant Field Values
      • FORMAT_DATE_INVERTED

        public static final java.lang.String FORMAT_DATE_INVERTED
        Constant attribute that represents the date format "dd-MM-yyyy".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_STANDARD_ADDITIONAL

        public static final java.lang.String FORMAT_DATE_TIME_STANDARD_ADDITIONAL
        Constant attribute that represents the date format "dd/MM/yyyy HH:mm:ss.SSS".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_MINUTES

        public static final java.lang.String FORMAT_DATE_TIME_MINUTES
        Constant attribute that represents the date format "dd-MMM-yyyy HH:mm".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_NOTFULL

        public static final java.lang.String FORMAT_DATE_TIME_NOTFULL
        Constant attribute that represents the date format "yyyy-MM-dd HH:mm:ss ZZZZ".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_UTC

        public static final java.lang.String FORMAT_DATE_TIME_UTC
        Constant attribute that represents the date format "yyyy-MM-dd'T'HH:mm:ss.SSS".
        See Also:
        Constant Field Values
      • FORMAT_DATE_ADDITIONAL

        public static final java.lang.String FORMAT_DATE_ADDITIONAL
        Constant attribute that represents the date format "yyyy/MM/dd EEE hh:mm:ss zzzz".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_SECONDS

        public static final java.lang.String FORMAT_DATE_TIME_SECONDS
        Constant attribute that represents the date format "dd-MM-yy_HH-mm-ss".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_ORACLE

        public static final java.lang.String FORMAT_DATE_TIME_ORACLE
        Constant attribute that represents the date format "MM/DD/YYYY HH24:MI:SS".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_MYSQL_HSQLDB

        public static final java.lang.String FORMAT_DATE_TIME_MYSQL_HSQLDB
        Constant attribute that represents the date format "YYYY/MM/DD HH24:MI:SS".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_XML_CONFIGURATION

        public static final java.lang.String FORMAT_DATE_TIME_XML_CONFIGURATION
        Constant attribute that represents the date format "yyyy-MM-dd HH:mm:ss.SSS zzz".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_CRL_ISSUE_TIME

        public static final java.lang.String FORMAT_DATE_TIME_CRL_ISSUE_TIME
        Constant attribute that represents the date format "yyyy-MM-dd'T'HH:mm:ss".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_TIMESTAMP

        public static final java.lang.String FORMAT_DATE_TIME_TIMESTAMP
        Constant attribute that represents the date format "yyyy-MM-dd'T'HH:mm:ss'.'SSS'Z'".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_JSON

        public static final java.lang.String FORMAT_DATE_TIME_JSON
        Constant attribute that represents the date format "yyyy-MM-dd'T'HH:mm:ss.SSSXXX".
        See Also:
        Constant Field Values
      • FORMAT_DATE_TIME_TSL

        public static final java.lang.String FORMAT_DATE_TIME_TSL
        Constant attribute that represents the date format "yyyy-MM-dd'T'HH:mm:ss'Z".
        See Also:
        Constant Field Values
    • Constructor Detail

      • UtilsDate

        public UtilsDate()
        Constructor method for the class UtilsDate.java.
      • UtilsDate

        public UtilsDate​(java.util.Date pFecha)
        Constructor method for the class UtilsDate.java.
        Parameters:
        pFecha - Parameter that represents the value of the date.
      • UtilsDate

        public UtilsDate​(java.util.Calendar c)
        Constructor method for the class UtilsDate.java.
        Parameters:
        c - Parameter that represents the object to set the value of the date and the time zone offset.
      • UtilsDate

        public UtilsDate​(java.util.TimeZone t)
        Constructor method for the class UtilsDate.java.
        Parameters:
        t - Parameter that represents the time zone offset.
      • UtilsDate

        public UtilsDate​(java.lang.String timezone)
        Constructor method for the class UtilsDate.java.
        Parameters:
        timezone - Parameter that represents the identifier for the time zone offset.
      • UtilsDate

        public UtilsDate​(java.lang.String dateString,
                         java.lang.String dateFormat)
                  throws java.text.ParseException
        Constructor method for the class UtilsDate.java.
        Parameters:
        dateString - Parameter that represents the value of the date.
        dateFormat - Parameter that represents the format used for the date.
        Throws:
        java.text.ParseException - If the method fails.
    • Method Detail

      • toString

        public final java.lang.String toString​(java.lang.String dateFormat)
        Method that obtains a string with the value of the date for certain format.
        Parameters:
        dateFormat - Parameter that represents the format to apply for the date.
        Returns:
        a string with the value of the date for certain format.
      • toString

        public static final java.lang.String toString​(java.lang.String dateFormat,
                                                      java.util.Date dateParam)
        Method that obtains a string with the value of the date for certain format.
        Parameters:
        dateFormat - Parameter that represents the format to apply for the date.
        dateParam - Date to be transform to String
        Returns:
        a string with the value of the date for certain format.
      • toString

        public final java.lang.String toString​(java.text.SimpleDateFormat simpleDateFormat)
        Method that obtains a string with the value of the date for certain format.
        Parameters:
        simpleDateFormat - Parameter that represents the concrete object for formatting and parsing the date in a locale-sensitive manner.
        Returns:
        a string with the value of the date for certain format.
      • toUTCString

        public final java.lang.String toUTCString()
        Method that obtains a string which represents the date on UTC format.
        Returns:
        the string on UTC format.
      • getUTCDate

        public static java.util.Date getUTCDate​(java.lang.String utcDate)
                                         throws java.text.ParseException
        Method that obtains a date from a string with UTC format.
        Parameters:
        utcDate - Parameter that represents the string with UTC format.
        Returns:
        the date.
        Throws:
        java.text.ParseException - If the method fails.
      • getSystemDate

        public static java.lang.String getSystemDate​(java.lang.String formato)
        Method that obtains the current date and time of the system.
        Parameters:
        formato - Parameter that represents the format used to obtain the date.
        Returns:
        the current date and hour of the system in the input format.
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        See Also:
        Object.toString()
      • getDate

        public final java.util.Date getDate()
        Gets the value of the attribute date.
        Returns:
        the value of the attribute date.
      • setDate

        public final void setDate​(java.util.Date pFecha)
        Sets the value of the attribute date.
        Parameters:
        pFecha - The value for the attribute date.
      • addDays

        public final void addDays​(int numDays)
        Method that adds a number of days to the date.
        Parameters:
        numDays - Parameter that represents the number of days to add.
      • modifyFormat

        public static java.lang.String modifyFormat​(java.lang.String initialDate,
                                                    java.lang.String originalFormat,
                                                    java.lang.String newFormat)
                                             throws java.text.ParseException
        Method that modifies the format of a date.
        Parameters:
        initialDate - Parameter that represents the date.
        originalFormat - Parameter that represents the original format.
        newFormat - Parameter that represents the new format.
        Returns:
        a string that represents the date with the new format.
        Throws:
        java.text.ParseException - If the method fails.
      • addDaysToSystemDate

        public final java.lang.String addDaysToSystemDate​(int numDays)
                                                   throws java.text.ParseException
        Method that adds a number of days to the system date.
        Parameters:
        numDays - Parameter that represents the number of days to add.
        Returns:
        a string that represents the date returned on format yyyy-mm-dd.
        Throws:
        java.text.ParseException - If the method fails.
      • getSystemDateAddingDays

        public static java.lang.String getSystemDateAddingDays​(java.lang.String initialDate,
                                                               int numDays)
                                                        throws java.text.ParseException
        Method that adds a number of days to certain date.
        Parameters:
        initialDate - Parameter that represents the date to add the days. It's a string with YYYYMMDD format.
        numDays - Parameter that represents the number of days to add.
        Returns:
        a string that represents the date returned on format yyyyMMDD.
        Throws:
        java.text.ParseException - If the method fails.
      • getDateAddingDays

        public static java.util.Date getDateAddingDays​(java.util.Date initialDate,
                                                       int numDays)
        Method that adds a number of days to certain date.
        Parameters:
        initialDate - Parameter that represents the date to add the days.
        numDays - Parameter that represents the number of days to add.
        Returns:
        a Date with diasAdd more.
      • transformDate

        public static java.util.Date transformDate​(java.lang.String initialDate,
                                                   java.lang.String pattern)
                                            throws java.text.ParseException
        Method that obtains a date from a string using a determined pattern.
        Parameters:
        initialDate - Parameter that represents the string to transform in date.
        pattern - Parameter that represents the pattern used to generate the date.
        Returns:
        a date from a string using a determined pattern.
        Throws:
        java.text.ParseException - If the method fails.
      • parseToPDFDate

        public static java.util.Date parseToPDFDate​(java.lang.String value)
        Method that returns a Date from a string representing a PDF Date conform to the ASN.1 date format. This consists of D:YYYYMMDDHHmmSSOHH'mm' where everything before and after YYYY is optional.
        Parameters:
        value - Parameter that represents the PDF Date.
        Returns:
        a wellformed Date if the input param is valid, or null in another case.
      • getPeriod

        public static java.lang.Long getPeriod​(java.lang.Long hourPeriod,
                                               java.lang.Long minutePeriod,
                                               java.lang.Long secondPeriod)
        Method that obtains a period in milliseconds.
        Parameters:
        hourPeriod - Parameter that represents the hour.
        minutePeriod - Parameter that represents the minutes.
        secondPeriod - Parameter that represents the seconds.
        Returns:
        the period in milliseconds or null if some of the values.
      • getHoursSecondsMinutes

        public static java.lang.Integer[] getHoursSecondsMinutes​(java.lang.Long milliseconds)
        Method that obtains the value in hours, minutes and seconds of a period in milliseconds.
        Parameters:
        milliseconds - Parameter that represents the period in milliseconds.
        Returns:
        an array where the first position is the value of the hour (24-hour), the second position is the value of the minutes and the third position is the value of the minutes.