Java Locale Format format(Date date, String pattern)

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

Description

format

License

LGPL

Declaration

public static String format(Date date, String pattern) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;

public class Main {

    public static String format(Date date, String pattern) {
        String result = null;//from  www  . j  a v  a2s. c  om
        result = "";
        if (date != null) {
            SimpleDateFormat formatter = new SimpleDateFormat();
            formatter.applyPattern(pattern);
            result = formatter.format(date);
        }
        return result;
    }

    public static String format(Date date, String pattern, String locale) {
        String result = null;
        result = "";
        if (date != null) {
            Locale _locale = null;
            try {
                _locale = new Locale(locale);
            } catch (Throwable t) {
                _locale = null;
            }
            SimpleDateFormat formatter = (_locale != null ? new SimpleDateFormat(pattern, _locale)
                    : new SimpleDateFormat(pattern));
            //formatter.applyPattern(pattern);
            result = formatter.format(date);
        }
        return result;
    }
}

Related

  1. format(Date date)
  2. format(Date date)
  3. format(Date date, String format)
  4. format(Date date, String format, Locale locale)
  5. format(Date date, String parttern)
  6. format(Date date, String pattern)
  7. format(Date date, String pattern, Locale locale)
  8. format(Date inputDate, String format, Locale locale)
  9. format(double d)