public class AS400Timestamp extends AS400AbstractTime
java.sql.Timestamp
object and
an IBM i timestamp value such as "1997-12-31-23.59.59.999999".
In the IBM i programming reference, this type is referred to as the
"Timestamp Data Type", or DDS data type Z.
The minimum value for an IBM i timestamp is 0001-01-01-00.00.00.000000, and the maximum value is 9999-12-31-24.00.00.000000.
Note that java.sql.Timestamp values have nanoseconds precision, whereas IBM i timestamp values have only microseconds precision. When converting Timestamp values to IBM i timestamp values, fractional microseconds are rounded to the nearest microsecond.
An IBM i timestamp value simply indicates a year/month/day/hour/minute/second/microsecond, and does not indicate a contextual time zone. Internally, this class interprets all date- and time-related strings as relative to time zone of the AS400 system.
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 time zone,
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 a server time zone.
For example:
import java.text.SimpleDateFormat;
java.sql.Timestamp timestamp1; // value to be generated by AS400Timestamp
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
// Set the formatter's time zone to the servers time zone
formatter.setTimeZone(as400.getTimeZone());
...
System.out.println("Timestamp value: " + formatter.format(timestamp1));
AS400Date
,
AS400Time
,
Serialized FormModifier and Type | Field and Description |
---|---|
static int |
FORMAT_DEFAULT
The standard IBM i timestamp format.
|
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 |
---|
AS400Timestamp()
Constructs an AS400Timestamp object.
|
AS400Timestamp(java.util.TimeZone timeZone)
Constructs an AS400Timestamp object.
|
AS400Timestamp(java.util.TimeZone timeZone,
int dataLength)
Constructs an AS400Timestamp object when datalength < 26.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
getDefaultValue()
Returns a Java object representing the default value of the data type.
|
int |
getInstanceType()
Returns
TYPE_TIMESTAMP . |
java.lang.Class |
getJavaType()
Returns the Java class that corresponds with this data type.
|
java.sql.Timestamp |
parse(java.lang.String source)
Converts a string representation of a timestamp, to a Java object.
|
static java.sql.Timestamp |
parseXsdString(java.lang.String source)
Converts the specified ISO representation of a timestamp, to a Java object.
|
static java.sql.Timestamp |
parseXsdString(java.lang.String source,
java.util.TimeZone timeZone)
Converts the specified ISO representation of a timestamp, to a Java 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.
|
java.util.Date |
toDate(java.sql.Timestamp timestamp,
java.util.TimeZone timezone)
Creates a new java.util.Date object representing the Timestamp's nominal value, in the context of the
specified time zone.
|
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.
|
java.sql.Timestamp |
toTimestamp(byte[] as400Value)
Converts the specified IBM i data type to a Java object.
|
java.sql.Timestamp |
toTimestamp(byte[] as400Value,
int offset)
Converts the specified IBM i data type to a Java object.
|
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.
|
clone, getByteLength, getTimeZone, toBytes, toBytes, toObject
public static final int FORMAT_DEFAULT
public AS400Timestamp()
public AS400Timestamp(java.util.TimeZone timeZone)
timeZone
- public AS400Timestamp(java.util.TimeZone timeZone, int dataLength)
timeZone
- dataLength
- public java.lang.Object getDefaultValue()
getDefaultValue
in interface AS400DataType
getDefaultValue
in class AS400AbstractTime
public int getInstanceType()
TYPE_TIMESTAMP
.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.Timestamp
.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.Timestamp
object corresponding to the data type.
The reference time zone for the object is GMT.public java.sql.Timestamp toTimestamp(byte[] as400Value)
toObject(byte[])
method.as400Value
- The array containing the data type in IBM i format. The entire data type must be represented.java.sql.Timestamp
object corresponding to the data type.
The reference time zone for the object is GMT.public java.sql.Timestamp toTimestamp(byte[] as400Value, int offset)
toObject(byte[],int)
method.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.Timestamp
object corresponding to the data type.
The reference time zone for the object is GMT.public java.util.Date toDate(java.sql.Timestamp timestamp, java.util.TimeZone timezone)
For example, if timestamp represents "2000-01-01-00.00.00.000000 GMT", and timezone specifies CST, then this method will return a java.util.Date object representing "2000-01-01-00.00.00.000000 CST".
Note that java.util.Date has milliseconds precision, whereas java.sql.Timestamp has nanoseconds precision. When converting from Timestamp to Date, nanoseconds are rounded to the nearest millisecond.
timestamp
- The timestamp object.timezone
- The desired reference time zone to assign to the returned Date object.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.Timestamp
,
and must be within the range specifiable by this data type.ExtendedIllegalArgumentException
- if the specified date is outside of the range representable by this data type.public java.sql.Timestamp parse(java.lang.String source)
source
- A timestamp value expressed as a string in standard IBM i timestamp
format.java.sql.Timestamp
object representing the specified timestamp.
The reference time zone for the object is GMT.public static java.sql.Timestamp parseXsdString(java.lang.String source)
source
- A timestamp value expressed as a string in format yyyy-MM-ddTHH:mm:ss.SSSSSSSSS.
For example: 2010-01-01T23:59:59.999999999java.sql.Timestamp
object representing the specified timestamp.public static java.sql.Timestamp parseXsdString(java.lang.String source, java.util.TimeZone timeZone)
source
- A timestamp value expressed as a string in format yyyy-MM-ddTHH:mm:ss.SSSSSSSSS.
For example: 2010-01-01T23:59:59.999999999timeZone
- time zone to used for the conversion.java.sql.Timestamp
object representing the specified timestamp.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.Timestamp
, 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.Timestamp
, and must be within the range specifiable by this data type.timeZone
- Time zone used to interpret the value.