com.ibm.commerce.utils
Class TimestampHelper

java.lang.Object
  |
  +--java.util.Date
        |
        +--java.sql.Timestamp
              |
              +--com.ibm.commerce.utils.TimestampHelper
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable

public class TimestampHelper
extends java.sql.Timestamp

TimestampHelper class contains helper methods for manipulating timestamps

See Also:
Serialized Form

Field Summary
static int MILLIS_IN_SECOND
           
static int SQL_TSI_SECOND
           
 
Constructor Summary
TimestampHelper(int year, int month, int date, int hour, int minute, int second, int nano)
          TimestampHelper constructor.
TimestampHelper(long time)
          TimestampHelper constructor.
 
Method Summary
static java.sql.Timestamp getCurrentTime()
          Returns current date and time of the executing system as a timestamp value.
static java.lang.String getDateFromTimestamp(java.sql.Timestamp t)
          Will extract the date portion from the timestamp The date will be returned as follows YYYY-MM-DD
static java.lang.String getDateFromTimestamp(java.sql.Timestamp t, java.util.Locale locale)
          Will extract the date portion from the timestamp The date will be returned in a locale specific manner
static java.lang.String getDateTimeFromTimestamp(java.sql.Timestamp t, java.util.Locale locale)
          The date and time will be returned in a locale specific format
static java.lang.String getDayFromTimestamp(java.sql.Timestamp t)
          Will extract the day portion from the timestamp
static java.lang.String getMonthFromTimestamp(java.sql.Timestamp t)
          Will extract the month portion from the timestamp
static java.lang.String getSQLCurrentTimestamp()
          Returns the SQL keyword for retrieving current timestamp
static java.lang.String getTimeFromTimestamp(java.sql.Timestamp t)
          Will extract the time portion from the timestamp The date will be returned as follows hh:mm in 24 hour form
static java.lang.String getTimestampString(java.lang.String pattern, java.sql.Timestamp t)
          Convert a timestamp to its string representation using the input pattern.
static java.lang.String getTimestampString(java.sql.Timestamp t)
          Convert a timestamp to its string representation using the pattern defined in the config file.
static java.lang.String getYearFromTimestamp(java.sql.Timestamp t)
          Will extract the year portion from the timestamp
static java.sql.Timestamp now()
          Returns current date and time from database as a timestamp value.
static java.sql.Timestamp parseDateTime(java.lang.String date, java.lang.String time)
          Will convert 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)
          Will convert the date, 3 vars YYYY, MM and DD and time in the form hh:mm into a timestamp
static java.sql.Timestamp systemCurrentTimestamp()
          Returns current date and time of the executing system as a timestamp value.
static java.sql.Timestamp timestampAdd(int interval, long numberOfIntervals, java.sql.Timestamp timestamp)
          Returns the timestamp calculated by adding numberOfIntervals intervals to timestamp.
static long timestampDiff(int interval, java.sql.Timestamp timestamp1, java.sql.Timestamp timestamp2)
          Returns the number of intervals of type interval by which timestamp1 is greater than timestamp2.
 
Methods inherited from class java.sql.Timestamp
after, before, equals, equals, getDate, getHours, getMinutes, getMonth, getNanos, getSeconds, getYear, setNanos, toString, valueOf
 
Methods inherited from class java.util.Date
after, before, clone, compareTo, compareTo, getDay, getTime, getTimezoneOffset, hashCode, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setTime, setYear, toGMTString, toLocaleString, UTC
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MILLIS_IN_SECOND

public static final int MILLIS_IN_SECOND

SQL_TSI_SECOND

public static final int SQL_TSI_SECOND
Constructor Detail

TimestampHelper

public TimestampHelper(int year,
                       int month,
                       int date,
                       int hour,
                       int minute,
                       int second,
                       int nano)
TimestampHelper constructor.

Parameters:
year - int
month - int
date - int
hour - int
minute - int
second - int
nano - int

TimestampHelper

public TimestampHelper(long time)
TimestampHelper constructor.

Parameters:
time - long
Method Detail

getCurrentTime

public static java.sql.Timestamp getCurrentTime()
Returns current date and time of the executing system as a timestamp value.
Returns:
java.sql.Timestamp

getDateFromTimestamp

public static java.lang.String getDateFromTimestamp(java.sql.Timestamp t)
Will extract the date portion from the timestamp The date will be returned as follows YYYY-MM-DD
Parameters:
t - Timestamp to parse
Returns:
date string Creation date: (8/16/00 6:50:03 PM)

getDateFromTimestamp

public static java.lang.String getDateFromTimestamp(java.sql.Timestamp t,
                                                    java.util.Locale locale)
Will extract the date portion from the timestamp The date will be returned in a locale specific manner
Parameters:
t - Timestamp to parse
locale - Locale to use for display
Returns:
date string

getDateTimeFromTimestamp

public static java.lang.String getDateTimeFromTimestamp(java.sql.Timestamp t,
                                                        java.util.Locale locale)
The date and time will be returned in a locale specific format
Parameters:
t - Timestamp to parse
locale - Locale to use for display
Returns:
date string

getDayFromTimestamp

public static java.lang.String getDayFromTimestamp(java.sql.Timestamp t)
Will extract the day portion from the timestamp
Parameters:
t - Timestamp to parse
Returns:
date string

getMonthFromTimestamp

public static java.lang.String getMonthFromTimestamp(java.sql.Timestamp t)
Will extract the month portion from the timestamp
Parameters:
t - Timestamp to parse
Returns:
date string

getSQLCurrentTimestamp

public static java.lang.String getSQLCurrentTimestamp()
Returns the SQL keyword for retrieving current timestamp

getTimeFromTimestamp

public static java.lang.String getTimeFromTimestamp(java.sql.Timestamp t)
Will extract the time portion from the timestamp The date will be returned as follows hh:mm in 24 hour form
Parameters:
t - Timestamp to parse
Returns:
time string

getTimestampString

public static java.lang.String getTimestampString(java.lang.String pattern,
                                                  java.sql.Timestamp t)
Convert a timestamp to its string representation using the input pattern. The default pattern will be returned on error.
Parameters:
pattern - String - time stamp pattern to be used
t - Timestamp to parse
Returns:
timestamp string

getTimestampString

public static java.lang.String getTimestampString(java.sql.Timestamp t)
Convert a timestamp to its string representation using the pattern defined in the config file. If no pattern is defined or if an error occurs. The default pattern will be returned
Parameters:
t - Timestamp to parse
Returns:
date string

getYearFromTimestamp

public static java.lang.String getYearFromTimestamp(java.sql.Timestamp t)
Will extract the year portion from the timestamp
Parameters:
t - Timestamp to parse
Returns:
date string

now

public static java.sql.Timestamp now()
Returns current date and time from database as a timestamp value.
Returns:
java.sql.Timestamp

parseDateTime

public static java.sql.Timestamp parseDateTime(java.lang.String date,
                                               java.lang.String time)
Will convert the date (YYYY-MM-DD) and time (hh:mm) into a timestamp
Parameters:
date - Date to use to create timestamp
time - Time to use to create timestamp
Returns:
timestamp Creation date: (8/16/00 6:50:03 PM)

parseDateTime

public static java.sql.Timestamp parseDateTime(java.lang.String year,
                                               java.lang.String month,
                                               java.lang.String day,
                                               java.lang.String time)
Will convert the date, 3 vars YYYY, MM and DD and time in the form hh:mm into a timestamp
Parameters:
date - Date to use to create timestamp
time - Time to use to create timestamp
Returns:
timestamp Creation date: (8/16/00 6:50:03 PM)

systemCurrentTimestamp

public static java.sql.Timestamp systemCurrentTimestamp()
Returns current date and time of the executing system as a timestamp value.
Returns:
java.sql.Timestamp

timestampAdd

public static java.sql.Timestamp timestampAdd(int interval,
                                              long numberOfIntervals,
                                              java.sql.Timestamp timestamp)
Returns the timestamp calculated by adding numberOfIntervals intervals to timestamp. Valid values of interval are the following keywords: SQL_TSI_SECOND (More constants can be added when required)
Parameters:
interval - keyword to represent unit of time such as second, minute.
numberOfIntervals - number of units of time
timestamp - the base timestamp
Returns:
java.sql.Timestamp

timestampDiff

public static long timestampDiff(int interval,
                                 java.sql.Timestamp timestamp1,
                                 java.sql.Timestamp timestamp2)
Returns the number of intervals of type interval by which timestamp1 is greater than timestamp2. Valid values of interval are the following keywords: SQL_TSI_SECOND (More constants can be added when required)
Parameters:
interval - keyword to represent unit of time such as second, minute
timestamp1 - java.sql.Timestamp
timestamp2 - java.sql.Timestamp
Returns:
difference between timestamp1 and timestamp2 in interval