Class UtilsTime


  • public class UtilsTime
    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, 25/08/2020.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String FORMATO_COMPLETO
      Constant attribute that represents the date format yyyy-MM-dd EEE HH:mm:ss ZZZZ.
      static java.lang.String FORMATO_COMPLETO_ADICIONAL
      Constant attribute that represents the date format "yyyy/MM/dd EEE hh:mm:ss zzzz".
      static java.lang.String FORMATO_FECHA
      Constant attribute that represents the date format yyyy-MM-dd.
      static java.lang.String FORMATO_FECHA_BAJA
      Constant attribute that represents the date format dd_MM_yyyy.
      static java.lang.String FORMATO_FECHA_BARRAS
      Constant attribute that represents the date format "dd/MM/yyyy/HH/mm/ss".
      static java.lang.String FORMATO_FECHA_CORTO
      Constant attribute that represents the date format dd/MM/yyyy.
      static java.lang.String FORMATO_FECHA_ESTANDAR
      Constant attribute that represents the date format "dd/MM/yyyy HH:mm:ss".
      static java.lang.String FORMATO_FECHA_ESTANDAR_ADICIONAL
      Constant attribute that represents the date format "dd/MM/yyyy HH:mm:ss.SSS".
      static java.lang.String FORMATO_FECHA_HORA
      Constant attribute that represents the date format yyyy-MM-dd HH:mm:ss.
      static java.lang.String FORMATO_FECHA_HORA_ADICIONAL
      Constant attribute that represents the date format "yyyy-MM-dd'T'HHmmssZ".
      static java.lang.String FORMATO_FECHA_HORA_COMPLETA
      Constant attribute that represents the date format "yyyy-MM-dd HH:mm:ss,SSS".
      static java.lang.String FORMATO_FECHA_HORA_MINUTOS
      Constant attribute that represents the date format "dd-MMM-yyyy HH:mm".
      static java.lang.String FORMATO_FECHA_HORA_SEGUNDOS
      Constant attribute that represents the date format "dd-MM-yy_HH-mm-ss".
      static java.lang.String FORMATO_FECHA_INVERTIDO
      Constant attribute that represents the date format "dd-MM-yyyy".
      static java.lang.String FORMATO_FECHA_JUNTA
      Constant attribute that represents the date format yyyyMMddHHmmss.
      static java.lang.String FORMATO_FECHA_JUNTA_ADICIONAL
      Constant attribute that represents the date format "yyyyMMddHHmmss.SZ".
      static java.lang.String FORMATO_FECHA_JUNTA_CORTA
      Constant attribute that represents the date format yyyyMMdd.
      static java.lang.String FORMATO_FECHA_UTC
      Constant attribute that represents the date format "yyyy-MM-dd'T'HH:mm:ss.SSS".
      static java.lang.String FORMATO_HORA
      Constant attribute that represents the date format HH:mm:ss.
      static java.lang.String FORMATO_SEMICOMPLETO
      Constant attribute that represents the date format "yyyy-MM-dd HH:mm:ss ZZZZ".
    • Constructor Summary

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Date convierteFecha​(java.lang.String fecha, java.lang.String patron)
      Method that obtains a date from a string using a determined pattern.
      java.util.Date getFecha()
      Gets the value of the attribute fecha.
      static java.lang.String getFechaMasNDias​(java.lang.String fechaEnt, int diasAdd)
      Method that adds a number of days to certain date.
      static java.lang.String getFechaSistema​(java.lang.String formato)
      Method that obtains the current date and hour of the system.
      static java.util.Date getUTCDate​(java.lang.String utcDate)
      Method that obtains a date from a string with UTC format.
      static java.lang.String modificarFormato​(java.lang.String fecha, java.lang.String formatoOriginal, java.lang.String nuevoFormato)
      Method that modifies the format of a date.
      void setFecha​(java.util.Date pFecha)
      Sets the value of the attribute fecha.
      void sumar​(int numDias)
      Method that adds a number of days to the date.
      java.lang.String sumarDias​(int numDias)
      Method that adds a number of days to the system date.
      java.lang.String toString()
      java.lang.String toString​(java.lang.String formato)
      Method that obtains a string with the value of the date for certain format.
      java.lang.String toString​(java.text.SimpleDateFormat formador)
      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.
      • Methods inherited from class java.lang.Object

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

      • FORMATO_COMPLETO

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

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

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

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

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

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

        public static final java.lang.String FORMATO_FECHA_JUNTA_CORTA
        Constant attribute that represents the date format yyyyMMdd.
        See Also:
        Constant Field Values
      • FORMATO_FECHA_BAJA

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

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

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

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

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

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

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

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

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

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

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

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

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

      • UtilsTime

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

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

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

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

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

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

      • toString

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

        public java.lang.String toString​(java.text.SimpleDateFormat formador)
        Method that obtains a string with the value of the date for certain format.
        Parameters:
        formador - 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 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.
      • getFechaSistema

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

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

        public java.util.Date getFecha()
        Gets the value of the attribute fecha.
        Returns:
        the value of the attribute fecha.
      • setFecha

        public void setFecha​(java.util.Date pFecha)
        Sets the value of the attribute fecha.
        Parameters:
        pFecha - The value for the attribute fecha.
      • sumar

        public void sumar​(int numDias)
        Method that adds a number of days to the date.
        Parameters:
        numDias - Parameter that represents the number of days to add.
      • modificarFormato

        public static java.lang.String modificarFormato​(java.lang.String fecha,
                                                        java.lang.String formatoOriginal,
                                                        java.lang.String nuevoFormato)
                                                 throws java.text.ParseException
        Method that modifies the format of a date.
        Parameters:
        fecha - Parameter that represents the date.
        formatoOriginal - Parameter that represents the original format.
        nuevoFormato - 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.
      • sumarDias

        public java.lang.String sumarDias​(int numDias)
                                   throws java.text.ParseException
        Method that adds a number of days to the system date.
        Parameters:
        numDias - 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.
      • getFechaMasNDias

        public static java.lang.String getFechaMasNDias​(java.lang.String fechaEnt,
                                                        int diasAdd)
                                                 throws java.text.ParseException
        Method that adds a number of days to certain date.
        Parameters:
        fechaEnt - Parameter that represents the date to add the days. It's a string with YYYYMMDD format.
        diasAdd - 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.
      • convierteFecha

        public static java.util.Date convierteFecha​(java.lang.String fecha,
                                                    java.lang.String patron)
                                             throws java.text.ParseException
        Method that obtains a date from a string using a determined pattern.
        Parameters:
        fecha - Parameter that represents the string to transform in date.
        patron - 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.