public class AS400Time extends AS400AbstractTime
java.sql.Time
object and an IBM i time
value such as "23:59:59" or "11:59 PM".
In the IBM i programming reference, this type is referred to as the "Time Data Type",
or DDS data type T.
An IBM i time value simply indicates an hour/minute/second within some (unspecified) 24-hour period, and does not indicate a contextual day, month, year, or time zone. Internally, this class interprets all date- and time-related strings as relative to the server's time zone.
Suggestion: To avoid confusion and unexpected results when crossing time zones:
Whenever creating or interpreting instances of java.sql.Date
,
java.sql.Time
, or java.sql.Timestamp
,
always assume that the reference time zone for the object is the server's time zone, and
avoid using any deprecated methods. If it is necessary to convert date/time values
between the server's time zone and other time zones, use methods of Calendar.
Rather than using toString() to display the value of a date/time object,
use DateFormat.format() after specifying the server timezone.
For example:
import java.text.SimpleDateFormat;
java.sql.Time time1; // value to be generated by AS400Time
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
// Set the formatter's time zone to the server timezone.
formatter.setTimeZone(as400.getTimeZone());
...
System.out.println("Time value: " + formatter.format(time1));
AS400Timestamp
,
AS400Date
,
Serialized FormModifier and Type | Field and Description |
---|---|
static int |
FORMAT_EUR
Format EUR: hh.mm.ss
Default separator: '.' |
static int |
FORMAT_HMS
Format HMS: hh:mm:ss
Default separator: ':' |
static int |
FORMAT_ISO
Format ISO: hh.mm.ss
Default separator: '.' |
static int |
FORMAT_JIS
Format JIS: hh:mm:ss
Default separator: ':' |
static int |
FORMAT_USA
Format USA: hh:mm AM or hh:mm PM
Default separator: ':' Note: Unlike the other formats, this format has a granularity of minutes rather than seconds. |
static java.sql.Time |
MAX_VALUE
The maximum value representable by this date type.
|
static java.sql.Time |
MIN_VALUE
The minimum value representable by this date type.
|
TYPE_ARRAY, TYPE_BIN1, TYPE_BIN2, TYPE_BIN4, TYPE_BIN8, TYPE_BYTE_ARRAY, TYPE_DATE, TYPE_DECFLOAT, TYPE_FLOAT4, TYPE_FLOAT8, TYPE_PACKED, TYPE_STRUCTURE, TYPE_TEXT, TYPE_TIME, TYPE_TIME_OF_DAY, TYPE_TIMESTAMP, TYPE_UBIN1, TYPE_UBIN2, TYPE_UBIN4, TYPE_UBIN8, TYPE_VARCHAR, TYPE_ZONED
Constructor and Description |
---|
AS400Time()
Constructs an AS400Time object.
|
AS400Time(int format)
Constructs an AS400Time object.
|
AS400Time(int format,
java.lang.Character separator)
Constructs an AS400Time object.
|
AS400Time(java.util.TimeZone timeZone)
Constructs an AS400Time object.
|
AS400Time(java.util.TimeZone timeZone,
int format)
Constructs an AS400Time object.
|
AS400Time(java.util.TimeZone timeZone,
int format,
java.lang.Character separator)
Constructs an AS400Time object.
|
Modifier and Type | Method and Description |
---|---|
static int |
getByteLength(int format,
java.lang.Character separator)
Returns the number of bytes occupied on the IBM i system by a field of this type.
|
java.lang.Object |
getDefaultValue()
Returns a Java object representing the default value of the data type.
|
int |
getFormat()
Gets the format of this AS400Time object.
|
int |
getInstanceType()
Returns
TYPE_TIME . |
java.lang.Class |
getJavaType()
Returns the Java class that corresponds with this data type.
|
java.lang.Character |
getSeparator()
Gets the separator character of this AS400Time object.
|
java.sql.Time |
parse(java.lang.String source)
Converts a string representation of a time, to a Java object.
|
static java.sql.Time |
parseXsdString(java.lang.String source)
Converts the specified HMS representation of a time, to a Java object.
|
static java.sql.Time |
parseXsdString(java.lang.String source,
java.util.TimeZone timeZone)
Converts the specified HMS representation of a time, to a Java object.
|
void |
setFormat(int format)
Sets the format of this AS400Time object.
|
void |
setFormat(int format,
char separator)
Deprecated.
Use
setFormat(int,Character) instead. |
void |
setFormat(int format,
java.lang.Character separator)
Sets the format of this AS400Time object.
|
int |
toBytes(java.lang.Object javaValue,
byte[] as400Value,
int offset)
Converts the specified Java object into IBM i format in the specified byte array.
|
static int |
toFormat(java.lang.String formatName)
Returns the integer format value that corresponds to specified format name.
|
java.lang.Object |
toObject(byte[] as400Value,
int offset)
Converts the specified IBM i data type to a Java object.
|
java.lang.String |
toString(java.lang.Object javaValue)
Converts the specified Java object into a String representation that is consistent with the format of this data type.
|
static java.lang.String |
toXsdString(java.lang.Object javaValue)
Converts the specified Java object into a String representation that is consistent with the format of this data type.
|
static java.lang.String |
toXsdString(java.lang.Object javaValue,
java.util.TimeZone timeZone)
Converts the specified Java object into a String representation that is consistent with the format of this data type.
|
static boolean |
validateFormat(int format)
Validates the specified format value.
|
clone, getByteLength, getTimeZone, toBytes, toBytes, toObject
public static final java.sql.Time MIN_VALUE
public static final java.sql.Time MAX_VALUE
public static final int FORMAT_HMS
public static final int FORMAT_ISO
public static final int FORMAT_USA
public static final int FORMAT_EUR
public static final int FORMAT_JIS
public AS400Time()
FORMAT_ISO
and separator '.' are used.public AS400Time(java.util.TimeZone timeZone)
FORMAT_ISO
and separator '.' are used.timeZone
- public AS400Time(int format)
format
- The format for this object.
For a list of valid values, refer to AS400Time(int,Character)
.public AS400Time(java.util.TimeZone timeZone, int format)
timeZone
- format
- The format for this object.
For a list of valid values, refer to AS400Time(int,Character)
.public AS400Time(int format, java.lang.Character separator)
format
- The format for this object.
Valid values are:
separator
- The separator character.
Valid values are:
public AS400Time(java.util.TimeZone timeZone, int format, java.lang.Character separator)
timeZone
- format
- The format for this object.
Valid values are:
separator
- The separator character.
Valid values are:
public int getFormat()
AS400Time(int,Character)
.public java.lang.Character getSeparator()
AS400Time(int,Character)
.
If the format contains no separators, null is returned.setFormat(int,Character)
public void setFormat(int format)
format
- The format for this object.
For a list of valid values, refer to AS400Time(int,Character)
.public void setFormat(int format, java.lang.Character separator)
format
- The format for this object.
For a list of valid values, refer to AS400Time(int,Character)
.separator
- The separator character.
For a list of valid values, refer to AS400Time(int,Character)
.
A null value indicates "no separator".
Refer to the IBM i programming reference to determine which separator characters are valid with each format.public void setFormat(int format, char separator)
setFormat(int,Character)
instead.format
- The format for this object.
For a list of valid values, refer to AS400Time(int,Character)
.separator
- The separator character.public static int toFormat(java.lang.String formatName)
formatName
- The format name.
Valid values are:
FORMAT_ISO
is returned.public java.lang.Object getDefaultValue()
getDefaultValue
in interface AS400DataType
getDefaultValue
in class AS400AbstractTime
java.sql.Time
object representing time 00:00:00 GMT (on January 1, 1970).public int getInstanceType()
TYPE_TIME
.getInstanceType
in interface AS400DataType
getInstanceType
in class AS400AbstractTime
public java.lang.Class getJavaType()
getJavaType
in interface AS400DataType
getJavaType
in class AS400AbstractTime
public int toBytes(java.lang.Object javaValue, byte[] as400Value, int offset)
toBytes
in interface AS400DataType
toBytes
in class AS400AbstractTime
javaValue
- The object corresponding to the data type. It must be an instance of java.sql.Time
.
The range of valid values is MIN_VALUE
through MAX_VALUE
.
Year, month, day-of-month, and fractional seconds are disregarded.as400Value
- The array to receive the data type in IBM i format. There must be enough space to hold the IBM i value.offset
- The offset into the byte array for the start of the IBM i value. It must be greater than or equal to zero.public java.lang.Object toObject(byte[] as400Value, int offset)
toObject
in interface AS400DataType
toObject
in class AS400AbstractTime
as400Value
- The array containing the data type in IBM i format. The entire data type must be represented.offset
- The offset into the byte array for the start of the IBM i value. It must be greater than or equal to zero.java.sql.Time
object, representing the number of milliseconds into the day.
The reference time zone for the object is the timezone specified on the constructor.public java.lang.String toString(java.lang.Object javaValue)
toString
in class AS400AbstractTime
javaValue
- The object corresponding to the data type. This must be an instance of java.sql.Time
,
and must be within the range representable by this data type. Any timezone context is disregarded.public java.sql.Time parse(java.lang.String source)
source
- A time value expressed as a string in the format specified for this AS400Time object.java.sql.Time
object representing the specified time.
The reference timezone is the timezone specified for the object.public static java.sql.Time parseXsdString(java.lang.String source)
source
- A time value expressed as a string in format HH:mm:ss.java.sql.Time
object representing the specified time.public static java.sql.Time parseXsdString(java.lang.String source, java.util.TimeZone timeZone)
source
- A time value expressed as a string in format HH:mm:ss.timeZone
- The time zone used to interpret the value.java.sql.Time
object representing the specified time.public static java.lang.String toXsdString(java.lang.Object javaValue)
javaValue
- The object corresponding to the data type. This must be an instance of java.sql.Time
, and must be within the range specifiable by this data type.public static java.lang.String toXsdString(java.lang.Object javaValue, java.util.TimeZone timeZone)
javaValue
- The object corresponding to the data type. This must be an instance of
java.sql.Time
, and must be within the range specifiable by this data type.timeZone
- The time zone used to interpret the value.public static boolean validateFormat(int format)
format
- The format.
For a list of valid values, refer to AS400Time(int,Character)
.public static int getByteLength(int format, java.lang.Character separator)
format
- The format. This argument is ignored.
For a list of valid values, refer to AS400Time(int,Character)
.separator
- The separator character. This argument is ignored.
For a list of valid values, refer to AS400Time(int,Character)
.