Java Locale Format formatDate(Date value, String pattern, TimeZone tz)

Here you can find the source of formatDate(Date value, String pattern, TimeZone tz)

Description

format the date with the given pattern.

License

Open Source License

Parameter

Parameter Description
value Date
pattern String the format pattern, for example, SimpleDate.PATTERN_US_DATE
tz TimeZone if null,will use the server's default timezone

Return

String the formated string

Declaration

public static String formatDate(Date value, String pattern, TimeZone tz) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

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

public class Main {
    /**// w w w .jav  a2 s  . co m
     * format the date with the given pattern.
     * 
     * @param value Date
     * @param pattern String the format pattern, for example,
     *            SimpleDate.PATTERN_US_DATE
     * @param tz TimeZone if null,will use the server's default timezone
     * @return String the formated string
     */
    public static String formatDate(Date value, String pattern, TimeZone tz) {

        if (value == null) {
            return "";
        }
        SimpleDateFormat formater = new SimpleDateFormat(pattern, Locale.US);
        if (tz != null) {
            formater.setTimeZone(tz);
        }
        return formater.format(value);
    }
}

Related

  1. formatDate(Date date, String format, String localeText)
  2. formatDate(Date date, String pattern)
  3. formatDate(Date date, String pattern)
  4. formatDate(Date date, String pattern, Locale locale)
  5. formatDate(Date date, String pPatern)
  6. formatDate(final Date dat, final String pattern)
  7. formatDate(final Date date, final String datepattern, TimeZone tz)
  8. formatDate(final Date date, final String format)
  9. formatDate(final Date date, final String pattren)