Java String to Date toDateFormat(String dateFormat, TimeZone tz, Locale locale)

Here you can find the source of toDateFormat(String dateFormat, TimeZone tz, Locale locale)

Description

Returns an initialized DateFormat object.

License

Apache License

Parameter

Parameter Description
dateFormat optional format string
tz a parameter
locale can be null if dateFormat is not null

Return

DateFormat object

Declaration

public static DateFormat toDateFormat(String dateFormat, TimeZone tz, Locale locale) 

Method Source Code

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

import java.text.DateFormat;

import java.text.SimpleDateFormat;

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

public class Main {
    /**// ww  w  . ja v  a2 s  .c om
     * Returns an initialized DateFormat object.
     *
     * @param dateFormat
     *            optional format string
     * @param tz
     * @param locale
     *            can be null if dateFormat is not null
     * @return DateFormat object
     */
    public static DateFormat toDateFormat(String dateFormat, TimeZone tz, Locale locale) {
        DateFormat df = null;
        if (dateFormat == null) {
            df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
        } else {
            df = new SimpleDateFormat(dateFormat);
        }
        df.setTimeZone(tz);
        return df;
    }
}

Related

  1. toDate(String value)
  2. toDateByFormat(String dateString, String formatStr)
  3. toDateByPattern(String dateTime)
  4. toDateFormat(Integer grain, TimeZone timeZone, String dateFormatArg)
  5. toDateFormat(String date)
  6. toDateOracle(Date d, String format, String hqlFormat)
  7. toDates(DateFormat format, String[] values)
  8. toDateString(Calendar cal)
  9. toDateString(Date date)