Java Locale Format formatDateByFormat(Date date, String format)

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

Description

format Date By Format

License

Apache License

Declaration

public static String formatDateByFormat(Date date, String format) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static String formatDateByFormat(Date date, String format) {
        String result = "";
        if (date != null) {
            try {
                SimpleDateFormat sdf = new SimpleDateFormat(format);
                result = sdf.format(date);
            } catch (Exception ex) {
                ex.printStackTrace();/*from   w w w  . java2 s .  co m*/
            }
        }
        return result;
    }

    public static String format(Date date, String format) {
        String result = "";
        try {
            if (date != null) {
                DateFormat dateFormat = new SimpleDateFormat(format);
                result = dateFormat.format(date);
            }
        } catch (Exception localException) {
        }
        return result;
    }

    public static String format(Date date) {
        return format(date, "yyyy-MM-dd");
    }
}

Related

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