|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.as400.access.AS400AbstractTime
com.ibm.as400.access.AS400Timestamp
public class AS400Timestamp
Provides a converter between a 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 FormField Summary | |
---|---|
static int |
FORMAT_DEFAULT
The standard IBM i timestamp format. |
Fields inherited from interface com.ibm.as400.access.AS400DataType |
---|
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_ZONED |
Constructor Summary | |
---|---|
AS400Timestamp()
Constructs an AS400Timestamp object. |
|
AS400Timestamp(TimeZone timeZone)
Constructs an AS400Timestamp object. |
Method Summary | |
---|---|
Object |
getDefaultValue()
Returns a Java object representing the default value of the data type. |
int |
getInstanceType()
Returns TYPE_TIMESTAMP . |
Class |
getJavaType()
Returns the Java class that corresponds with this data type. |
Timestamp |
parse(String source)
Converts a string representation of a timestamp, to a Java object. |
static Timestamp |
parseXsdString(String source)
Converts the specified ISO representation of a timestamp, to a Java object. |
static Timestamp |
parseXsdString(String source,
TimeZone timeZone)
Converts the specified ISO representation of a timestamp, to a Java object. |
int |
toBytes(Object javaValue,
byte[] as400Value,
int offset)
Converts the specified Java object into IBM i format in the specified byte array. |
Date |
toDate(Timestamp timestamp,
TimeZone timezone)
Creates a new java.util.Date object representing the Timestamp's nominal value, in the context of the specified time zone. |
Object |
toObject(byte[] as400Value,
int offset)
Converts the specified IBM i data type to a Java object. |
String |
toString(Object javaValue)
Converts the specified Java object into a String representation that is consistent with the format of this data type. |
Timestamp |
toTimestamp(byte[] as400Value)
Converts the specified IBM i data type to a Java object. |
Timestamp |
toTimestamp(byte[] as400Value,
int offset)
Converts the specified IBM i data type to a Java object. |
static String |
toXsdString(Object javaValue)
Converts the specified Java object into a String representation that is consistent with the format of this data type. |
static String |
toXsdString(Object javaValue,
TimeZone timeZone)
Converts the specified Java object into a String representation that is consistent with the format of this data type. |
Methods inherited from class com.ibm.as400.access.AS400AbstractTime |
---|
clone, getByteLength, getTimeZone, toBytes, toBytes, toObject |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int FORMAT_DEFAULT
Constructor Detail |
---|
public AS400Timestamp()
public AS400Timestamp(TimeZone timeZone)
Method Detail |
---|
public Object getDefaultValue()
getDefaultValue
in interface AS400DataType
getDefaultValue
in class AS400AbstractTime
public int getInstanceType()
TYPE_TIMESTAMP
.
getInstanceType
in interface AS400DataType
getInstanceType
in class AS400AbstractTime
public Class getJavaType()
getJavaType
in interface AS400DataType
getJavaType
in class AS400AbstractTime
public int toBytes(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 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 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 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 Date toDate(Timestamp timestamp, 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 String toString(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 Timestamp parse(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 Timestamp parseXsdString(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.999999999
java.sql.Timestamp
object representing the specified timestamp.public static Timestamp parseXsdString(String source, 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 String toXsdString(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 String toXsdString(Object javaValue, 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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |