Java Utililty Methods SQL Time Parse

List of utility methods to do SQL Time Parse

Description

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

Method

java.util.DateparseDateTime(String original, int type)
parse Date Time
String s = original;
if (s == null) {
    return null;
try {
    int timeStart = 0;
    TimeZone tz = null;
    if (type == TIME) {
...
TimeparseTime(String s)
parse Time
if (s == null) {
    return null;
try {
    return new Time(simpleTimeFormat.parse(s).getTime());
} catch (ParseException e) {
    return null;
longparseTime(String str)
Parse the given string as a time, using the following time pattern: hh:mm:ss[.fffffffff] .
String nanos_s;
long hour;
long minute;
long second;
long a_nanos = 0;
String formatError = "Timestamp format must be hh:mm:ss[.fffffffff]";
String zeros = "000000000";
if (str == null)
...
TimeparseTime(String timeString)
parseTime: Returns a Time SQL object corresponding to the given time string.
Date javaDate = null;
try {
    javaDate = new SimpleDateFormat("hh:mm aaa").parse(timeString);
} catch (ParseException e) {
if (javaDate == null) {
    try {
        javaDate = new SimpleDateFormat("hh aaa").parse(timeString);
...
StringprintTime(Time time, String format)
Print the time in the format.
if (time == null) {
    return "";
return new SimpleDateFormat(format).format(time);
java.sql.Timestampstring2Time(String dateString)
string Time
DateFormat dateFormat;
dateFormat = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss", Locale.ENGLISH);
dateFormat.setLenient(false);
java.util.Date timeDate = dateFormat.parse(dateString);
java.sql.Timestamp dateTime = new java.sql.Timestamp(timeDate.getTime());
return dateTime;
Timestring2Time(String time, DateFormat timeFormat)
string Time
if (time == null)
    return null;
return new Time(string2Date(time, timeFormat).getTime());
TimestampstringToTime(String data, String dateFormat)
StringToDate Convert String to Timestamp
if (data == null || data.isEmpty())
    return null;
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
ParsePosition pos = new ParsePosition(0);
java.util.Date date = null;
Timestamp timestamp = null;
date = formatter.parse(data, pos);
timestamp = new Timestamp(date.getTime());
...
TimestringToTime(String schedule)
string To Time
if (schedule == null || schedule.isEmpty())
    return null;
String[] parts = schedule.split(SEPARATOR);
if (parts.length != 3)
    return null;
int hour = Integer.parseInt(parts[0]);
int minute = Integer.parseInt(parts[1]);
int second = Integer.parseInt(parts[2]);
...
TimestringToTime(String sTime)
string To Time
SimpleDateFormat stringToTime = new SimpleDateFormat("HH:mm:ss");
Calendar cal = GregorianCalendar.getInstance();
cal.setTimeInMillis(stringToTime.parse(sTime).getTime());
return new Time(cal.getTimeInMillis());