Java Utililty Methods SQL Time Create

List of utility methods to do SQL Time Create

Description

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

Method

longgetTimeLong(ResultSet resultSet)
get Time Long
try {
    String time = resultSet.getString("time");
    return formatter.parse(time).getTime();
} catch (Exception e) {
    try {
        Time time = resultSet.getTime("time");
        return time.getTime();
    } catch (Exception e2) {
...
intgetTimeNumberFromSqlTime(Time time)
get Time Number From Sql Time
Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
final int hour = calendar.get(Calendar.HOUR);
final int minute = calendar.get(Calendar.MINUTE);
final int second = calendar.get(Calendar.SECOND);
final int milli = calendar.get(Calendar.MILLISECOND);
return hour * 60 * 60 * 1000 + minute * 60 * 1000 + second * 1000 + milli;
TimestampgetTimesByStr(String dataStr)
get Times By Str
Date d = getDate(dataStr);
String newTime = getString2(d);
return Timestamp.valueOf(newTime);
StringgetTimeStr(Time time)
get Time Str
return FORMAT_HMS.format(time);
TimeZonegetTimeZone(String id)
Get timezone from Id.
TimeZone tz = TimeZone.getTimeZone(id);
if (tz.getID().equals("GMT") && !id.equals("GMT")) {
    throw new SQLException("invalid timezone id '" + id + "'");
return tz;
StringgetTimeZone(String timezone, String time, DateFormat format)
get Time Zone
try {
    time = time.trim();
    if (time.endsWith(":00")) {
        time = time.substring(0, time.length() - 3) + "00";
    Date date = parseDateStringToDate(format, time);
    Calendar ca = Calendar.getInstance();
    ca.clear();
...
StringgetTodayAndTime()
get Today And Time
return new Timestamp(System.currentTimeMillis()).toString();
TimestampgetTomorrowOrderTime()
get Tomorrow Order Time
LocalTime midnight = LocalTime.of(11, 00);
LocalDate today = LocalDate.now(ZoneId.systemDefault());
LocalDateTime todayMidnight = LocalDateTime.of(today, midnight);
LocalDateTime tomorrowMidnight = todayMidnight.plusDays(1);
return new Timestamp(Date.from(tomorrowMidnight.atZone(ZoneId.systemDefault()).toInstant()).getTime());
TimestampgetUserToServerDateTime(TimeZone timeZone, int dateFormat, int timeFormat, String date, Locale locale)
Gets the userToServerDateTime attribute of the DateUtils class
try {
    DateFormat localeFormatter = DateFormat.getDateInstance(dateFormat, locale);
    if (timeZone != null) {
        localeFormatter.setTimeZone(timeZone);
    localeFormatter.setLenient(false);
    return new Timestamp(localeFormatter.parse(date).getTime());
} catch (Exception e) {
...
longgetWaitTimeout(Connection con)
get Wait Timeout
Statement stmt = null;
ResultSet rs = null;
try {
    stmt = con.createStatement();
    rs = stmt.executeQuery("SHOW VARIABLES LIKE 'wait_timeout'");
    if (rs.next()) {
        return Math.max(1000, rs.getInt(2) * 1000 - 1000);
    } else {
...