Java Utililty Methods SQL Date Convert

List of utility methods to do SQL Date Convert

Description

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

Method

StringdateToStamp(String date)
date To Stamp
try {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(TIME_FORMAT);
    Date date1 = simpleDateFormat.parse(date);
    long ts = date1.getTime() / 1000;
    return String.valueOf(ts);
} catch (Exception e) {
return String.valueOf(getDateStamp() / 1000);
...
StringdateToSTR(Date data, String formato)
Formata um objeto java.sql.Date para String no formato passado como parametro.
if (data == null)
    return "";
SimpleDateFormat spd = new SimpleDateFormat(formato);
return spd.format(data).trim();
StringdateToStr(java.util.Date date)
date To Str
if (date == null) {
    return null;
} else {
    return (new SimpleDateFormat(simDateFormat)).format(date);
StringdateToString(Date date)
date To String
return dateToString(date, DEFAULT_DATETIME_PATTERN_WITHOUT_MILLISECONDS);
StringdateToString(Date date, String format)

Description:Change the java.sql.Timestamp format to java.util.String format

try {
    SimpleDateFormat myFormatter = new SimpleDateFormat(format);
    return myFormatter.format(date);
} catch (Exception err) {
    return "";
StringdateToString(java.sql.Date d)
dateToString takes a JDBC date and makes it a mm/dd string
if (d == null)
    return "";
String s = d.toString(); 
if (s == null)
    if (s.equals("null"))
        return "";
StringTokenizer tk = new StringTokenizer(s, "-");
int yr = Integer.parseInt(tk.nextToken());
...
StringdateToString(java.sql.Date data)
date To String
String dta;
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
dta = sdf.format(data);
return dta;
StringdateToString(java.sql.Date datee)
date To String
return datee.toString();
StringdateToString(java.util.Date date, String dateFmt)
date To String
String strTemp = null;
if (date != null) {
    String dtFmt = dateFmt;
    if (null == dtFmt)
        dtFmt = "yyyy-MM-dd";
    SimpleDateFormat formatter = new SimpleDateFormat(dtFmt);
    strTemp = formatter.format(date);
return strTemp;
Stringto2GMTString(final Date tsStart, final Date tsEnd)
to GMT String
return timestampToString(new Timestamp(tsStart.getTime()), STANDARD_DATETIMEFORMAT, TZ_UTC) + " - "
        + timestampToString(new Timestamp(tsEnd.getTime()), STANDARD_DATETIMEFORMAT, TZ_UTC) + " GMT";