public class TimestampHelper
extends java.sql.Timestamp
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
COPYRIGHT
IBM Copyright notice field.
|
static int |
MILLIS_IN_SECOND
The number of milliseconds in a second (1000).
|
static int |
SQL_TSI_SECOND
Has a value of 2.
|
Constructor and Description |
---|
TimestampHelper(int year,
int month,
int date,
int hour,
int minute,
int second,
int nano)
This is a constructor for this class.
|
TimestampHelper(long time)
This is a constructor for this class.
|
Modifier and Type | Method and Description |
---|---|
static java.sql.Timestamp |
getCurrentTime()
This method returns the current date and time of the executing system as a timestamp value.
|
static java.sql.Timestamp |
getCurrentTime(ActivityToken aToken)
This method returns a date.
|
static java.lang.String |
getDateFromTimestamp(java.sql.Timestamp t)
This method extracts the date portion from the timestamp.
|
static java.lang.String |
getDateFromTimestamp(java.sql.Timestamp t,
java.util.Locale locale)
This method extracts the date portion from the timestamp.
|
static java.lang.String |
getDateTimeFromTimestamp(java.sql.Timestamp t,
java.util.Locale locale)
This method returns the date and time in a locale-specific format.
|
static java.lang.String |
getDayFromTimestamp(java.sql.Timestamp t)
This method extracts the day portion from the timestamp.
|
static java.lang.String |
getMonthFromTimestamp(java.sql.Timestamp t)
This method extracts the month portion from the timestamp.
|
static java.lang.String |
getSQLCurrentTimestamp()
This method returns the
SQL keyword for retrieving current timestamp. |
static java.lang.String |
getSQLSyntaxTimestampPlusInteger(java.util.List parameters,
java.lang.String TimeStampAttribute,
java.lang.String IntegerAttribute)
This method creates a parameterized
SQL snippet to add an integer to a timestamp. |
static java.lang.String |
getSQLSyntaxTimestampPlusInteger(java.lang.String TimeStampAttribute,
java.lang.String IntegerAttribute)
This method creates an
SQL snippet to add an integer to a timestamp. |
static java.lang.String |
getTimeFromTimestamp(java.sql.Timestamp t)
This method extracts the time portion from the timestamp.
|
static java.lang.String |
getTimeFromTimestampWithSeconds(java.sql.Timestamp t)
This method extracts the time with second portion from the timestamp.
|
static java.lang.String |
getTimestampString(java.lang.String pattern,
java.sql.Timestamp t)
This method convert a timestamp to its
String representation using the input pattern. |
static java.lang.String |
getTimestampString(java.sql.Timestamp t)
This method converts a timestamp to its
String representation using the pattern defined in the configuration file. |
static java.lang.String |
getYearFromTimestamp(java.sql.Timestamp t)
This method extracts the year portion from the timestamp.
|
static java.sql.Timestamp |
now()
This method returns current date and time from database as a timestamp value.
|
static java.sql.Timestamp |
parseDateTime(java.lang.String date,
java.lang.String time)
This method converts the date (
YYYY-MM-DD ) and time (hh:mm )
into a timestamp. |
static java.sql.Timestamp |
parseDateTime(java.lang.String year,
java.lang.String month,
java.lang.String day,
java.lang.String time)
This method converts the date, 3 variables
YYYY , MM and DD and time in the
form hh:mm into a timestamp. |
static java.sql.Timestamp |
systemCurrentTimestamp()
This method returns current time of the executing system as a timestamp value.
|
static java.sql.Timestamp |
timestampAdd(int interval,
long numberOfIntervals,
java.sql.Timestamp timestamp)
This method returns the timestamp calculated by adding
numberOfIntervals to
the timestamp. |
static long |
timestampDiff(int interval,
java.sql.Timestamp timestamp1,
java.sql.Timestamp timestamp2)
This method returns the number of intervals of type interval by which
timestamp1 is greater
than timestamp2 . |
static long |
timestampDifference(int interval,
java.sql.Timestamp timestamp1,
java.sql.Timestamp timestamp2)
This method returns the number of intervals of type interval by which
timestamp1 is greater
than timestamp2 . |
after, before, compareTo, compareTo, equals, equals, from, getNanos, getTime, hashCode, setNanos, setTime, toInstant, toLocalDateTime, toString, valueOf, valueOf
public static final java.lang.String COPYRIGHT
public static final int SQL_TSI_SECOND
public static final int MILLIS_IN_SECOND
public TimestampHelper(int year, int month, int date, int hour, int minute, int second, int nano)
year
- The year.month
- The month.date
- The day.hour
- The hour.minute
- The minute.second
- The second.nano
- The nanosecond.public TimestampHelper(long time)
long
format.time
- The time.public static java.sql.Timestamp getCurrentTime()
public static java.sql.Timestamp getCurrentTime(ActivityToken aToken)
aToken
- An activity token for this request.public static java.lang.String getDateFromTimestamp(java.sql.Timestamp t)
YYYY-MM-DD
.timestamp
- The Timestamp
object to convert.String
representation of the given Timestamp
.public static java.lang.String getDateFromTimestamp(java.sql.Timestamp t, java.util.Locale locale)
timestamp
- The Timestamp
object to parse.locale
- The locale to use for display.String
representation of the given timestamp.public static java.lang.String getDateTimeFromTimestamp(java.sql.Timestamp t, java.util.Locale locale)
timestamp
- The Timestamp
object to parse.locale
- The locale to use for display.String
representation of the specified timestamp.public static java.lang.String getDayFromTimestamp(java.sql.Timestamp t)
timestamp
- The Timestamp
object to parse.public static java.lang.String getMonthFromTimestamp(java.sql.Timestamp t)
timestamp
- The Timestamp
object to parse.public static java.lang.String getSQLCurrentTimestamp()
SQL
keyword for retrieving current timestamp.CURRENT_TIMESTAMP
" will be
returned. Otherwise "CURRENT TIMESTAMP" will be returned.public static java.lang.String getSQLSyntaxTimestampPlusInteger(java.lang.String TimeStampAttribute, java.lang.String IntegerAttribute)
SQL
snippet to add an integer to a timestamp. It is returned in the correct
syntax depending on DBMS
.
Creation date: (9/17/2001 3:54:13 PM)TimeStampAttribute
- A java.lang.String
object.IntegerAttribute
- A java.lang.String
object.java.lang.String
object.public static java.lang.String getSQLSyntaxTimestampPlusInteger(java.util.List parameters, java.lang.String TimeStampAttribute, java.lang.String IntegerAttribute)
SQL
snippet to add an integer to a timestamp. It is returned in the correct
syntax depending on DBMS
. It adds the integer to a list of parameters.
Creation date: (9/17/2001 3:54:13 PM)parameters
- A list of parameters.TimeStampAttribute
- A java.lang.String
object.IntegerAttribute
- A java.lang.String
object.SQL
snippet as a java.lang.String
object.public static java.lang.String getTimeFromTimestamp(java.sql.Timestamp t)
hh:mm
in 24 hour form.timestamp
- The Timestamp
object to parse.String
representation of the time contained in the given timestamp.public static java.lang.String getTimeFromTimestampWithSeconds(java.sql.Timestamp t)
hh:mm:ss
in 24 hour formtimestamp
- The Timestamp
object to parse.String
representation of the time contained in the given timestamp.public static java.lang.String getTimestampString(java.lang.String pattern, java.sql.Timestamp t)
String
representation using the input pattern.
The default pattern will be returned on error.pattern
- The timestamp pattern to be used.timestamp
- The Timestamp
object to parse.String
representation of the specified timestamp based on the given pattern.public static java.lang.String getTimestampString(java.sql.Timestamp t)
String
representation using the pattern defined in the configuration file.
If no pattern is defined or if an error occurs, the default pattern will be returned.timestamp
- The Timestamp
object to parse.String
representation of the specified timestamp.public static java.lang.String getYearFromTimestamp(java.sql.Timestamp t)
timestamp
- The Timestamp
object to parse.public static java.sql.Timestamp now()
public static java.sql.Timestamp parseDateTime(java.lang.String date, java.lang.String time)
YYYY-MM-DD
) and time (hh:mm
)
into a timestamp.date
- The date to use to create the timestamp.time
- The time to use to create the timestamp.Timestamp
object that represents the given date and time.public static java.sql.Timestamp parseDateTime(java.lang.String year, java.lang.String month, java.lang.String day, java.lang.String time)
YYYY
, MM
and DD
and time in the
form hh:mm
into a timestamp.year
- The year to use to create the timestamp.month
- The month to use to create the timestamp.day
- The day to use to create the timestamp.time
- The time to use to create timestampTimestamp
object that represents the given year, month, day and time.public static java.sql.Timestamp systemCurrentTimestamp()
public static java.sql.Timestamp timestampAdd(int interval, long numberOfIntervals, java.sql.Timestamp timestamp)
numberOfIntervals
to
the timestamp. Valid values for an interval are the following keywords:
SQL_TSI_SECOND.interval
- A keyword to represent a unit of time such as second or a minute.numberOfIntervals
- The number of units of time.timestamp
- The base timestamp.public static long timestampDiff(int interval, java.sql.Timestamp timestamp1, java.sql.Timestamp timestamp2)
timestamp1
is greater
than timestamp2
. Valid values for an interval are the following keywords:
SQL_TSI_SECOND.interval
- A keyword to represent a unit of time such as second or a minute.timestamp1
- The first timestamp.timestamp2
- The second timestamp to subtract from the first one.timestamp1
and timestamp2
in intervals.public static long timestampDifference(int interval, java.sql.Timestamp timestamp1, java.sql.Timestamp timestamp2)
timestamp1
is greater
than timestamp2
. Valid values for an interval are specified in seconds. So, if the interval
required is a day, 86400 is specified.interval
- The interval required in secondstimestamp1
- A java.sql.Timestamp
object.timestamp2
- A java.sql.Timestamp
object.timestamp1
and timestamp2
in intervals.