Java Utililty Methods Timestamp Field

List of utility methods to do Timestamp Field

Description

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

Method

java.sql.TimestampgetDayEnd(java.sql.Timestamp stamp, int daysLater)
get Day End
Calendar tempCal = Calendar.getInstance();
tempCal.setTime(new java.util.Date(stamp.getTime()));
tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), 23,
        59, 59);
tempCal.add(Calendar.DAY_OF_MONTH, daysLater);
return new java.sql.Timestamp(tempCal.getTime().getTime());
intgetDayOfMonthBy(Timestamp ts)
get Day Of Month By
Calendar calendar = getCalendar();
if (ts != null)
    calendar.setTimeInMillis(ts.getTime());
return calendar.get(Calendar.DAY_OF_MONTH);
intgetDayOfTime(Timestamp timestamp)
get Day Of Time
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timestamp.getTime());
return calendar.get(Calendar.DAY_OF_MONTH);
intgetDayOfWeek(Timestamp timestamp)
get Day Of Week
Calendar cal = Calendar.getInstance();
Date date = new Date(timestamp.getTime());
cal.setTime(date);
int dayForWeek = 0;
dayForWeek = cal.get(Calendar.DAY_OF_WEEK);
if (dayForWeek == 1) {
    dayForWeek = 7;
} else {
...
intgetDaysBetween(Timestamp start, Timestamp end)
Calculate the number of days between start and end.
boolean negative = false;
if (end.before(start)) {
    negative = true;
    Timestamp temp = start;
    start = end;
    end = temp;
GregorianCalendar cal = new GregorianCalendar();
...
longgetDayStartTimestamp()
get Day Start Timestamp
Timestamp[] timestamps = getDayStartEnd();
return Long.valueOf(dateToStamp(timestamps[0] + ""));
TimestampgetDayTime(Timestamp day, Timestamp time)
Return the day and time
GregorianCalendar cal_1 = new GregorianCalendar();
cal_1.setTimeInMillis(day.getTime());
GregorianCalendar cal_2 = new GregorianCalendar();
cal_2.setTimeInMillis(time.getTime());
GregorianCalendar cal = new GregorianCalendar();
cal.set(cal_1.get(Calendar.YEAR), cal_1.get(Calendar.MONTH), cal_1.get(Calendar.DAY_OF_MONTH),
        cal_2.get(Calendar.HOUR_OF_DAY), cal_2.get(Calendar.MINUTE), cal_2.get(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, 0);
...
TimestampgetDefaultTimestamp()
Creates a default timestamp.
return new Timestamp(new Date().getTime());
intgetDiffDay(Timestamp time1, Timestamp time2)
get Diff Day
return getDay1(new Date(time2.getTime()), new Date(time1.getTime()));
doublegetDifferenceInHours(Timestamp startDateTime, Timestamp endDateTime)
get Difference In Hours
int difference = 0;
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(startDateTime);
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(endDateTime);
Calendar startCompare = Calendar.getInstance();
startCompare.setTime(startDateTime);
startCompare.set(Calendar.HOUR_OF_DAY, 0);
...