Java Utililty Methods SQL Date From

List of utility methods to do SQL Date From

Description

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

Method

StringconvertTime2String(long time)
convert Time String
return convertTS2String(new Timestamp(time));
TimestampconvertTime2TS(long time)
convert Time TS
return new Timestamp(time);
doubleconvertTimeToHour(long time)
convert Time To Hour
return convertTimeToDay(time) * 24;
DateconvertToDateTime(java.util.Date date, String time)
convert To Date Time
Calendar calendar = new GregorianCalendar();
String[] timeArray = getTime(time);
calendar.setTime(date);
calendar.set(Calendar.HOUR, Integer.parseInt(timeArray[0]));
calendar.set(Calendar.MINUTE, Integer.parseInt(timeArray[1]));
return new Date(calendar.getTime().getTime());
java.sql.TimeconvertToTime(Date toDate)
convert To Time
java.sql.Time sql = null;
sql = new java.sql.Time(toDate.getTime());
return sql;
TimeconvertToTime(java.util.Date date)
Converts java.util.Date to java.sql.Time

normalize year=1970,,month=1,day=1.

if (date == null) {
    throw new IllegalArgumentException("date msut not be null");
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.YEAR, DEFUALT_YEAR);
cal.set(Calendar.MONTH, 0);
cal.set(Calendar.DAY_OF_MONTH, 1);
...
TimeZonegetCNTimezone()
get CN Timezone
return TimeZone.getTimeZone("Asia/Shanghai");
StringgetCurAllTime()
RETURN DATE STRING FORMAT "yyyy-MM-dd HH:mm:ss"
Timestamp ts = null;
try {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String d = sdf.format(new java.util.Date());
    ts = Timestamp.valueOf(d);
} catch (Exception ex) {
    ex.printStackTrace();
return ts.toString().substring(0, 19);
StringgetCurrDateTime()
get Curr Date Time
java.sql.Timestamp date = new java.sql.Timestamp(System.currentTimeMillis());
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
return formatter.format(date);
StringgetCurrentDateTime()
get Current Date Time
return getCurrentTime(DEFAULT_DATE_PATTERN);