public class AS400Date extends AS400AbstractTime
java.sql.Date
object and an IBM i date value such
as "12/31/97".
In the IBM i programming reference, this type is referred to as the "Date Data Type", or
DDS data type L. Note: Only date fields that are stored on the IBM i system as EBCDIC characters
are currently supported by this class. (Some IBM i "logical files" have date fields stored as zoned or
packed decimal values.)
An IBM i date value simply indicates a year/month/day, and does not indicate a contextual time zone. Internally, this class interprets all date- and time-related strings as relative to the timezone of the server.
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 same
as the server, and avoid using any deprecated methods. If it is necessary to convert date/time values between
the server 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.Date date1; // value to be generated by AS400Date
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
// Set the formatter's time zone to GMT.
formatter.setTimeZone(as400.getTimeZone());
...
System.out.println("Date value: " + formatter.format(date1));
Suggestion: To avoid ambiguity and confusion between different kinds of "Date" objects, fully qualify all references to classes java.util.Date and java.sql.Date (especially if you import both java.util.* and java.sql.*).
Note: In the descriptions of the "format" constants, all example dates represent the date April 25, 1997.
AS400Time
,
AS400Timestamp
,
Serialized FormModifier and Type | Field and Description |
---|---|
static int |
FORMAT_CDMY
Date format CDMY (cdd/mm/yy).
|
static int |
FORMAT_CMDY
Date format CMDY (cmm/dd/yy).
|
static int |
FORMAT_CYMD
Date format CYMD (cyy/mm/dd).
|
static int |
FORMAT_DMY
Date format DMY (dd/mm/yy).
|
static int |
FORMAT_EUR
Date format EUR (dd.mm.yyyy).
|
static int |
FORMAT_ISO
Date format ISO (yyyy-mm-dd).
|
static int |
FORMAT_JIS
Date format JIS (yyyy-mm-dd).
|
static int |
FORMAT_JUL
Date format JUL (yy/ddd).
|
static int |
FORMAT_LONGJUL
Date format LONGJUL (yyyy/ddd).
|
static int |
FORMAT_MDY
Date format MDY (mm/dd/yy).
|
static int |
FORMAT_MY
Date format MY (mm/yy).
|
static int |
FORMAT_MYY
Date format MYY (mm/yyyy).
|
static int |
FORMAT_USA
Date format USA (mm/dd/yyyy).
|
static int |
FORMAT_YM
Date format YM (yy/mm).
|
static int |
FORMAT_YMD
Date format YMD (yy/mm/dd).
|
static int |
FORMAT_YYM
Date format YYM (yyyy/mm).
|
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 |
---|
AS400Date()
Constructs an AS400Date object.
|
AS400Date(int format)
Constructs an AS400Date object.
|
AS400Date(int format,
java.lang.Character separator)
Constructs an AS400Date object.
|
AS400Date(java.util.TimeZone timeZone)
Constructs an AS400Date object.
|
AS400Date(java.util.TimeZone timeZone,
int format)
Constructs an AS400Date object.
|
AS400Date(java.util.TimeZone timeZone,
int format,
java.lang.Character separator)
Constructs an AS400Date 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 AS400Date object.
|
int |
getInstanceType()
Returns
TYPE_DATE . |
java.lang.Class |
getJavaType()
Returns the Java class that corresponds with this data type.
|
java.lang.Character |
getSeparator()
Gets the separator character of this AS400Date object.
|
java.sql.Date |
parse(java.lang.String source)
Converts a string representation of a date, to a Java object.
|
static java.sql.Date |
parseXsdString(java.lang.String source)
Converts the specified ISO representation of a date, to a Java object.
|
static java.sql.Date |
parseXsdString(java.lang.String source,
java.util.TimeZone timeZone)
Converts the specified ISO representation of a date, to a Java object.
|
void |
setFormat(int format)
Sets the format of this AS400Date 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 AS400Date 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 an XML Schema string representation.
|
static java.lang.String |
toXsdString(java.lang.Object javaValue,
java.util.TimeZone timeZone)
Converts the specified Java object into an XML Schema string representation.
|
static boolean |
validateFormat(int format)
Validates the specified format value.
|
clone, getByteLength, getTimeZone, toBytes, toBytes, toObject
public static final int FORMAT_MDY
public static final int FORMAT_DMY
public static final int FORMAT_YMD
public static final int FORMAT_JUL
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 static final int FORMAT_CYMD
public static final int FORMAT_CMDY
public static final int FORMAT_CDMY
public static final int FORMAT_LONGJUL
public static final int FORMAT_MY
public static final int FORMAT_YM
public static final int FORMAT_MYY
public static final int FORMAT_YYM
public AS400Date()
FORMAT_ISO
and separator '-' are used.public AS400Date(java.util.TimeZone timeZone)
FORMAT_ISO
and separator '-' are used.timeZone
- timezone to use for this datepublic AS400Date(int format)
format
- The date format.
For a list of valid values, refer to AS400Date(int,Character)
.public AS400Date(java.util.TimeZone timeZone, int format)
timeZone
- Time zone to use for this object.format
- The date format.
For a list of valid values, refer to AS400Date(int,Character)
.public AS400Date(int format, java.lang.Character separator)
format
- The date format.
separator
- The separator character.
Valid values are:
public AS400Date(java.util.TimeZone timeZone, int format, java.lang.Character separator)
timeZone
- time zone.format
- The date format.
separator
- The separator character.
Valid values are:
public java.lang.Object getDefaultValue()
getDefaultValue
in interface AS400DataType
getDefaultValue
in class AS400AbstractTime
public int getFormat()
AS400Date(int,Character)
.public java.lang.Character getSeparator()
AS400Date(int,Character)
.
If the format contains no separators, null is returned.setFormat(int,Character)
public int getInstanceType()
TYPE_DATE
.getInstanceType
in interface AS400DataType
getInstanceType
in class AS400AbstractTime
public java.lang.Class getJavaType()
getJavaType
in interface AS400DataType
getJavaType
in class AS400AbstractTime
public void setFormat(int format)
format
- The format for this object.
For a list of valid values, refer to AS400Date(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 AS400Date(int,Character)
.separator
- The separator character.
For a list of valid values, refer to AS400Date(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 AS400Date(int,Character)
.separator
- The separator character.public static int toFormat(java.lang.String formatName)
formatName
- The date format name.
FORMAT_ISO
is returned.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.Date
. Hours, minutes, seconds, and milliseconds 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.Date
object corresponding to the data type.
The reference time zone for the object is GMT.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.Date
, and must be within the range specifiable by this data type.public java.sql.Date parse(java.lang.String source)
source
- A date value expressed as a string in the format specified for this AS400Date object.java.sql.Date
object representing the specified date.
The reference time zone for the object is GMT.public static java.sql.Date parseXsdString(java.lang.String source)
source
- A date value expressed as a string in format yyyy-MM-dd.java.sql.Date
object representing the specified date.public static java.sql.Date parseXsdString(java.lang.String source, java.util.TimeZone timeZone)
source
- A date value expressed as a string in format yyyy-MM-dd.timeZone
- Time zone used by the date.java.sql.Date
object representing the specified date.
The reference time zone must be passed as a parameter.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.Date
,
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.Date
,
and must be within the range specifiable by this data type.timeZone
- The timezone used to evaluate the string.public static boolean validateFormat(int format)
format
- The format.
For a list of valid values, refer to AS400Date(int,Character)
.public static int getByteLength(int format, java.lang.Character separator)
format
- The format.
For a list of valid values, refer to AS400Date(int,Character)
.separator
- The separator character.
For a list of valid values, refer to AS400Date(int,Character)
.