com.ibm.as400.access

Class DateTimeConverter

  • java.lang.Object
    • com.ibm.as400.access.DateTimeConverter


  • public class DateTimeConverter
    extends java.lang.Object
    A utility for converting date/time values. The system API QWCCVTDT is used to convert a date and time value from one format to another format.
    See Also:
    AS400Date, AS400Time, AS400Timestamp
    • Constructor Summary

      Constructors 
      Constructor and Description
      DateTimeConverter(AS400 system)
      Constructs a DateTimeConverter object.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      java.util.Date convert(byte[] data, java.lang.String inFormat)
      Returns a converted Date object.
      byte[] convert(byte[] data, java.lang.String inFormat, java.lang.String outFormat)
      Converts date and time values from the input format to the requested output format.
      byte[] convert(java.util.Date date, java.lang.String outFormat)
      Returns the converted date and time in a byte array.
      static java.util.TimeZone timeZoneForSystem(AS400 system)
      Returns a TimeZone object to represent the time zone for the specified system.
      • Methods inherited from class java.lang.Object

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

      • DateTimeConverter

        public DateTimeConverter(AS400 system)
        Constructs a DateTimeConverter object.
        Parameters:
        system - The system.
    • Method Detail

      • convert

        public byte[] convert(byte[] data,
                     java.lang.String inFormat,
                     java.lang.String outFormat)
                       throws AS400SecurityException,
                              ErrorCompletingRequestException,
                              java.lang.InterruptedException,
                              java.io.IOException,
                              ObjectDoesNotExistException
        Converts date and time values from the input format to the requested output format. The system API QWCCVTDT (Convert Date and Time Format) is called to perform the conversion.

        This method effectively just re-arranges the time format and returns it. The input and output values are relative to the same time zone. Therefore, no adjustments are made based on time-zone.

        Parameters:
        data - The date and time value to be converted.
        inFormat - The input date and time format. Possible values are:
        • *CURRENT
        • *DTS
        • *JOB
        • *SYSVAL
        • *YMD
        • *YYMD
        • *MDY
        • *MDYY
        • *DMY
        • *DMYY
        • *JUL
        • *LONGJUL
        outFormat - The output date and time format. Possible values are:
        • *DTS
        • *JOB
        • *SYSVAL
        • *YMD
        • *YYMD
        • *MDY
        • *MDYY
        • *DMY
        • *DMYY
        • *JUL
        • *LONGJUL
        • *DOS
        Returns:
        The converted date and time value, left-justified in the array. Refer to the specification for the QWCCVTDT API to determine how many of the returned bytes are meaningful.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        ErrorCompletingRequestException - If an error occurs before the request is completed.
        java.lang.InterruptedException - If this thread is interrupted.
        java.io.IOException - If an error occurs while communicating with the system.
        ObjectDoesNotExistException - If the object does not exist on the system.
      • convert

        public java.util.Date convert(byte[] data,
                             java.lang.String inFormat)
                               throws AS400SecurityException,
                                      ErrorCompletingRequestException,
                                      java.lang.InterruptedException,
                                      java.io.IOException,
                                      ObjectDoesNotExistException
        Returns a converted Date object. The system API QWCCVTDT (Convert Date and Time Format) is called to perform the conversion.
        Parameters:
        data - The date and time value to be converted. The value is assumed to be relative to the IBM i system's time zone.
        inFormat - The format of the date and time value being provided. Possible values are:
        • *CURRENT
        • *DTS
        • *JOB
        • *SYSVAL
        • *YMD
        • *YYMD
        • *MDY
        • *MDYY
        • *DMY
        • *DMYY
        • *JUL
        • *LONGJUL
        Note: When *CURRENT is specified, the data parameter is disregarded.
        Returns:
        The converted date and time.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        ErrorCompletingRequestException - If an error occurs before the request is completed.
        java.lang.InterruptedException - If this thread is interrupted.
        java.io.IOException - If an error occurs while communicating with the system.
        ObjectDoesNotExistException - If the object does not exist on the system.
      • convert

        public byte[] convert(java.util.Date date,
                     java.lang.String outFormat)
                       throws AS400SecurityException,
                              ErrorCompletingRequestException,
                              java.lang.InterruptedException,
                              java.io.IOException,
                              ObjectDoesNotExistException
        Returns the converted date and time in a byte array.
        Parameters:
        date - The Date object to be converted.
        outFormat - The format of the returned date and time value. Possible values are:
        • *DTS
        • *JOB
        • *SYSVAL
        • *YMD
        • *YYMD
        • *MDY
        • *MDYY
        • *DMY
        • *DMYY
        • *JUL
        • *LONGJUL
        Returns:
        The converted date and time value, left-justified in the array. The context of the value is the IBM i system's time zone. Refer to the specification for the QWCCVTDT API to determine how many of the returned bytes are meaningful.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        ErrorCompletingRequestException - If an error occurs before the request is completed.
        java.lang.InterruptedException - If this thread is interrupted.
        java.io.IOException - If an error occurs while communicating with the system.
        ObjectDoesNotExistException - If the object does not exist on the system.
      • timeZoneForSystem

        public static java.util.TimeZone timeZoneForSystem(AS400 system)
                                                    throws AS400SecurityException,
                                                           ErrorCompletingRequestException,
                                                           java.lang.InterruptedException,
                                                           java.io.IOException,
                                                           ObjectDoesNotExistException
        Returns a TimeZone object to represent the time zone for the specified system. The TimeZone object will have the correct UTC offset for the system.
        Parameters:
        system - The IBM i system.
        Returns:
        A TimeZone object representing the time zone for the system.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        ErrorCompletingRequestException - If an error occurs before the request is completed.
        java.lang.InterruptedException - If this thread is interrupted.
        java.io.IOException - If an error occurs while communicating with the system.
        ObjectDoesNotExistException - If the API used to retrieve the information does not exist on the system.
        See Also:
        AS400.getTimeZone()