Java Locale Format formatDate2String(Date date, String format)

Here you can find the source of formatDate2String(Date date, String format)

Description

format Date String

License

Open Source License

Declaration

public static final String formatDate2String(Date date, String format) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

public class Main {
    public static final String formatDate2String(Date date, String format) {
        if (isNull(date))
            return null;
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        String dateString = "";
        try {/*w  ww.  j av a  2 s.  c om*/
            dateString = sdf.format(date);
        } catch (Exception e) {
            //logger.error(e.getMessage());
        }
        return dateString;
    }

    public static final String formatDate2String(Date date, String format, Locale locale) {
        if (isNull(date))
            return null;
        SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
        String dateString = "";
        try {
            dateString = sdf.format(date);
        } catch (Exception e) {
            //logger.error(e.getMessage());
        }
        return dateString;
    }

    public static final boolean isNull(Object str) {
        return (str == null || str.toString().trim().length() == 0);
    }
}

Related

  1. formatDate(String dateStr, String format, String toFormat)
  2. formatDate(String pattern, Date date, String valueForNull)
  3. formatDate(String strDate, Locale locale)
  4. formatDate(String value, Locale locale)
  5. formatDate2Date(Date date, String format)
  6. formatDateByFormat(Date date, String format)
  7. formatDateTime(final Date date)
  8. formatDateTime(java.util.Date date, String format, String locale, String timeZone)
  9. formatDateToSQLString(Date srcDate)