Android SQL Date Format formatDate(java.util.Date value, String defaultFormat)

Here you can find the source of formatDate(java.util.Date value, String defaultFormat)

Description

format Date

Declaration

public static String formatDate(java.util.Date value,
            String defaultFormat) 

Method Source Code

import java.sql.Time;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.TimeZone;

public class Main{
    public final static String ISO_DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
    public final static String ISO_DATE_FORMAT = "yyyy-MM-dd";
    public static String formatDate(Timestamp value) {
        return formatDateTime(value, ISO_DATE_FORMAT);
    }/*from w w  w .j  a  va2 s .c  o m*/
    public static String formatDate(Timestamp value, String defaultFormat) {
        if (value == null) {
            return "";
        }
        String strFormatStyle = StringUtils.isEmpty(defaultFormat) ? ISO_DATE_FORMAT
                : defaultFormat;
        SimpleDateFormat objSimpleDateFormat = new SimpleDateFormat(
                strFormatStyle);
        return objSimpleDateFormat.format(value);
    }
    public static String formatDate(java.sql.Date value) {
        return formatDate(value, ISO_DATE_FORMAT);
    }
    public static String formatDate(java.util.Date value) {
        return formatDate(value, ISO_DATE_FORMAT);
    }
    public static String formatDate(java.util.Date value,
            String defaultFormat) {
        if (value == null) {
            return "";
        }
        String strFormatStyle = StringUtils.isEmpty(defaultFormat) ? ISO_DATE_FORMAT
                : defaultFormat;
        SimpleDateFormat objSimpleDateFormat = new SimpleDateFormat(
                strFormatStyle);
        return objSimpleDateFormat.format(value);
    }
    public static String formatDate(java.sql.Date value,
            String defaultFormat) {
        if (value == null) {
            return "";
        }
        String strFormatStyle = StringUtils.isEmpty(defaultFormat) ? ISO_DATE_FORMAT
                : defaultFormat;
        SimpleDateFormat objSimpleDateFormat = new SimpleDateFormat(
                strFormatStyle);
        return objSimpleDateFormat.format(value);
    }
    public static String formatDateTime(Timestamp value) {
        return formatDateTime(value, ISO_DATETIME_FORMAT);
    }
    public static String formatDateTime(Timestamp value,
            String defaultFormat) {
        if (value == null) {
            return "";
        }
        String strFormatStyle = StringUtils.isEmpty(defaultFormat) ? ISO_DATETIME_FORMAT
                : defaultFormat;
        SimpleDateFormat objSimpleDateFormat = new SimpleDateFormat(
                strFormatStyle);
        return objSimpleDateFormat.format(value);
    }
}

Related

  1. formatDate(java.sql.Date value)
  2. formatDate(java.sql.Date value, String defaultFormat)
  3. formatDate(java.util.Date value)
  4. DateToStringSQL(Date date, String separador)
  5. DateToString(Date date, String separador)
  6. DateToString(Date date)
  7. date2String(java.sql.Date date)