Java Utililty Methods SQL Time

List of utility methods to do SQL Time

Description

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

Method

intcompareTime(String time1, String time2)
compare Time
Date newDate1 = parseDate("1990-01-01 " + time1, "yyyy-MM-dd HH:mm:ss");
Date newDate2 = parseDate("1990-01-01 " + time2, "yyyy-MM-dd HH:mm:ss");
if (getMillis(newDate1) - getMillis(newDate2) > 0)
    return 1;
else if (getMillis(newDate1) - getMillis(newDate2) < 0)
    return -1;
return 0;
TimecreateTime(int hour, int minute, int second)
Replaces deprecated java.sql.Time constructor.
primeCalendar();
CAL.get().set(Calendar.HOUR_OF_DAY, hour);
CAL.get().set(Calendar.MINUTE, minute);
CAL.get().set(Calendar.SECOND, second);
return new Time(CAL.get().getTimeInMillis());
StringdateTime2str(java.sql.Date date)
date Timestr
if (date == null)
    return "";
try {
    return MMddYYYY_HHmmss.format(date);
} catch (Exception e) {
    return "";
StringdateTimeFormat(Date date, String pattern)
date Time Format
String s = "";
try {
    SimpleDateFormat dformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    s = dformat.format(date);
    s = String.valueOf(StrToTimestamp(s, pattern));
    s = s.substring(0, pattern.length());
} catch (Exception e) {
return s;
longDateTimeSpace(String starttime, String endtime)
Date Time Space
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long starttimes = 0;
long endtimes = 0;
long spacetime = 0;
try {
    starttimes = sdf.parse(starttime).getTime();
    endtimes = sdf.parse(endtime).getTime();
} catch (ParseException e) {
...
StringdateTimeToStr(java.util.Date date)
date Time To Str
if (date == null) {
    return null;
} else {
    return (new SimpleDateFormat(SimpleDateTimeFormat)).format(date);
Timedaytime()
Gets the current time.
return new Time(System.currentTimeMillis());
TimedeserializeSqlTime(String text)
Deserialize time from text.
if (text == null) {
    return null;
} else {
    return new Time(parseTime(text, 0, text.length()));
Timedouble2Time(Number zahl)
double Time
Time t = null;
if (zahl != null) {
    double d = (zahl.doubleValue() * (double) 3600000) - 3600000;
    t = new Time((long) d);
return t;
booleanequalsTime(Time time1, Time time2)
equals Time
boolean result = false;
if (time1 != null && time2 != null) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(time1);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.YEAR, 1970);
    calendar.set(Calendar.MILLISECOND, 0);
...