Java Utililty Methods SQL Date Format

List of utility methods to do SQL Date Format

Description

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

Method

StringdateFormat(Object obj, String parten)
date Format
if (obj == null)
    return null;
if (parten == null || parten.trim().length() == 0)
    parten = "yyyy-MM-dd";
SimpleDateFormat dateFormat = new SimpleDateFormat(parten);
if (obj instanceof java.sql.Date) {
    return dateFormat.format(obj);
} else if (obj instanceof java.util.Date) {
...
StringdateFormat(String sdate, String format)
date Format
SimpleDateFormat formatter = new SimpleDateFormat(format);
java.sql.Date date = java.sql.Date.valueOf(sdate);
String dateString = formatter.format(date);
return dateString;
StringdateFormatJson(Date date)
date Format Json
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DAY_OF_MONTH);
return year + "," + month + "," + day;
java.sql.DatedateFromLong(Long longObject)
Answer a Date from a long This implementation is based on the java.sql.Date class, not java.util.Date.
return new java.sql.Date(longObject.longValue());
StringformataData(Date data)
formata Data
return formataData(data, "dd/MM/yyyy");
voidformatAsText(ResultSet result_set, PrintWriter out)
Formats the ResultSet as plain mono-spaced text and outputs the result to the PrintWriter.
ResultSetMetaData meta_data = result_set.getMetaData();
int[] max_widths = new int[meta_data.getColumnCount()];
Vector[] data = new Vector[meta_data.getColumnCount()];
for (int i = 0; i < data.length; ++i) {
    data[i] = new Vector();
int row_count = 0;
for (int i = 0; i < data.length; ++i) {
...
StringformatBytableCols(Object[] obj, String[] tableCols)
format Bytable Cols
StringBuffer result = new StringBuffer();
result.append("{");
if (obj != null && obj.length > 0) {
    for (int i = 0; i < obj.length; i++) {
        try {
            result.append(tableCols[i]);
            result.append(":'");
            if (obj[i] instanceof String) {
...
StringformatDate(java.util.Date uDate)

formatDate

Dinh dang ngay kieu java.util.Date thanh String theo mau "dd/MM/yyyy"
if (uDate == null) {
    return null;
} else {
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    return dateFormat.format(uDate);
StringformatDate(Object obj)
format Date
String out = "";
if (obj == null) {
    return out;
try {
    Date dateval = (Date) obj;
    if (dateval != null) {
        SimpleDateFormat dateformat = new SimpleDateFormat("MM/dd/yyyy");
...
StringformatDate(String date)
format Date
return formatDate(Integer.valueOf(date));