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

java.util.DateStrToDateTime(String val)
Convert a string date in the YYYY-MM-DD HH:MM format into a java.util.Date object.
Calendar cal = Calendar.getInstance();
if (val != null) {
    StringTokenizer main = new StringTokenizer(val, " ");
    StringTokenizer st = new StringTokenizer(main.nextToken(), "-");
    cal.set(Calendar.YEAR, Integer.parseInt(st.nextToken()));
    cal.set(Calendar.MONTH, Integer.parseInt(st.nextToken()) - 1);
    cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(st.nextToken()));
    StringTokenizer temptime = new StringTokenizer(main.nextToken(), ":");
...
java.sql.TimestrToTime(String strDate)
str To Time
String str = strDate;
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
java.util.Date d = null;
try {
    d = format.parse(str);
} catch (Exception e) {
    e.printStackTrace();
java.sql.Time time = new java.sql.Time(d.getTime());
return time.valueOf(str);
DatetoDate(TimeZone tz, int days)
Returns the SQL Date object matching the given bytes with Oid#DATE .
long secs = toJavaSecs(days * 86400L);
long millis = secs * 1000L;
int offset = tz.getOffset(millis);
if (millis <= DATE_NEGATIVE_SMALLER_INFINITY) {
    millis = DATE_NEGATIVE_INFINITY;
    offset = 0;
} else if (millis >= DATE_POSITIVE_SMALLER_INFINITY) {
    millis = DATE_POSITIVE_INFINITY;
...
DatetoDateFromTime(String time)
to Date From Time
try {
    return toDateFromTime(Long.parseLong(time));
} catch (Exception iae) {
    return null;
TimestamptodayBeginTime()
today Begin Time
return Timestamp.valueOf(LocalDate.now().atStartOfDay());
longtoGMTTime(long local)
to GMT Time
SimpleDateFormat sdf = new SimpleDateFormat(DEFAULT_TIMESTAMP_FORMAT);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
ParsePosition pos = new ParsePosition(0);
java.util.Date date = sdf.parse(new Timestamp(local).toString(), pos);
if (date == null) {
    return -1;
return date.getTime();
...
TimestamptoMySQLDate(LocalDateTime dateTime)
to My SQL Date
return Timestamp.valueOf(dateTime);
long[]toPOSIXTime(String timeString)
to POSIX Time
return toPOSIXTime(new String[] { timeString });
DatetruncateTimePartOfDate(Date date)
Treats the input date as a date with UTC time and truncates the time part.
if (date == null) {
    return null;
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
...
StringunformattedFromTime(java.sql.Time t)
Convert from a Time to an unlocalized string with the format hhmmss.
return unformattedFromTime(t, false);