Java Utililty Methods Timestamp

List of utility methods to do Timestamp

Description

The list of methods to do Timestamp are organized into topic(s).

Method

StringdateToOracleStr(java.sql.Timestamp ts)
Contains some Oracle specific fixes to the timestamp.
StringBuffer tsString = new StringBuffer("null");
if (ts != null) {
    tsString.append("to_date('").append(ts.toString().substring(0, 19))
            .append("','YYYY-MM-DD HH24:MI:SS')");
return tsString.toString();
intdayNumber(Timestamp stamp)
returns a day number in a week for a Timestamp input
Calendar tempCal = toCalendar(stamp, TimeZone.getDefault(), Locale.getDefault());
return tempCal.get(Calendar.DAY_OF_WEEK);
longdaysBetween(Timestamp t1, Timestamp t2)
days Between
return (t2.getTime() - t1.getTime()) / DAY_MILLI;
Integerdelta_hours(Timestamp startdate, Timestamp enddate)
Returns the difference between two dates in hours
Long span;
if (startdate == null || enddate == null)
    return null;
span = (enddate.getTime() - startdate.getTime()) / 1000 / 60 / 60;
return span.intValue();
intdifferDayByNow(Timestamp timestamp)
differ Day By Now
return (int) (differMsByNow(timestamp) / 1000 / 60 / 60 / 24);
TimestampdoubleToTimestamp(double f)
double To Timestamp
try {
    long seconds = (long) f;
    BigDecimal bd = new BigDecimal(String.valueOf(f));
    bd = bd.subtract(new BigDecimal(seconds)).multiply(new BigDecimal(1000000000));
    int nanos = bd.intValue();
    long millis = seconds * 1000;
    if (nanos < 0) {
        millis -= 1000;
...
BigDecimaldurationBetween(Timestamp startedAt, Timestamp completedAt)
duration Between
if (completedAt == null) {
    return null;
long millis = completedAt.getTime() - startedAt.getTime();
return new BigDecimal(millis).divide(new BigDecimal(1000)).setScale(3, RoundingMode.HALF_EVEN);
ByteBufferencodeTimestamp(Timestamp timestamp)
Encodes a TIMESTAMP value.
if (timestamp == null)
    throw new NullPointerException("timestamp cannot be null.");
ByteBuffer buffer = ByteBuffer.allocate(8 + 4);
buffer.putLong(timestamp.getTime() / 1000);
buffer.putInt(timestamp.getNanos());
buffer.rewind();
return buffer;
java.sql.TimestampendOfMonth(java.sql.Timestamp dd)
covert Timestamp to end of day in month, 23:59:59 leaving date part untouched
Calendar cal = GregorianCalendar.getInstance(utcTZ);
cal.setTime(dd);
cal = endOfMonth(cal);
java.sql.Timestamp rval = new java.sql.Timestamp(cal.getTime().getTime());
return rval;
TimestampextractDateSystemTimeStamp()
Extract date form system and converts into TimeStamp SQL type
Calendar calendario = Calendar.getInstance();
Timestamp timestamp = new Timestamp(calendario.getTimeInMillis());
return timestamp;