Java Utililty Methods Locale Format

List of utility methods to do Locale Format

Description

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

Method

StringformatDate(String dateStr, String format, String toFormat)
format Date
return format(parseDate(dateStr, format), toFormat);
StringformatDate(String pattern, Date date, String valueForNull)
format Date
return date == null ? valueForNull : new SimpleDateFormat(pattern, Locale.getDefault()).format(date);
StringformatDate(String strDate, Locale locale)
format Date
String ret = "";
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date date = null;
try {
    date = sdf.parse(strDate);
} catch (Exception e) {
    return ret;
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, locale);
ret = df.format(date);
return ret;
DateformatDate(String value, Locale locale)

Checks if the field is a valid date.

Date date = null;
if (value != null) {
    try {
        DateFormat formatter = null;
        if (locale != null) {
            formatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
        } else {
            formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
...
DateformatDate2Date(Date date, String format)
format Date Date
return formatString2Date(formatDate2String(date, format), format);
StringformatDate2String(Date date, String format)
format Date String
if (isNull(date))
    return null;
SimpleDateFormat sdf = new SimpleDateFormat(format);
String dateString = "";
try {
    dateString = sdf.format(date);
} catch (Exception e) {
return dateString;
StringformatDateByFormat(Date date, String format)
format Date By Format
String result = "";
if (date != null) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        result = sdf.format(date);
    } catch (Exception ex) {
        ex.printStackTrace();
return result;
StringformatDateTime(final Date date)
Formats a date string using the currently selected locale.
Preconditions.checkNotNull(date, "Error: Date argument can't be null.");
return DateFormat.getDateTimeInstance().format(date);
StringformatDateTime(java.util.Date date, String format, String locale, String timeZone)
Formats a date using a format string.
SimpleDateFormat dateFormat = getDateFormat(format, locale, timeZone);
synchronized (dateFormat) {
    return dateFormat.format(date);
StringformatDateToSQLString(Date srcDate)
format Date To SQL String
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
return sdf.format(srcDate);