Java TimeZone Format toTimeFormat(String timeFormat, TimeZone tz, Locale locale)

Here you can find the source of toTimeFormat(String timeFormat, TimeZone tz, Locale locale)

Description

Returns an initialized DateFormat object.

License

Apache License

Parameter

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

Return

DateFormat object

Declaration

public static DateFormat toTimeFormat(String timeFormat, 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 {
    /**//from w  ww. j a va 2 s .  co m
     * Returns an initialized DateFormat object.
     *
     * @param timeFormat
     *            optional format string
     * @param tz
     * @param locale
     *            can be null if timeFormat is not null
     * @return DateFormat object
     */
    public static DateFormat toTimeFormat(String timeFormat, TimeZone tz, Locale locale) {
        DateFormat df = null;
        if (timeFormat == null) {
            df = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
        } else {
            df = new SimpleDateFormat(timeFormat);
        }
        df.setTimeZone(tz);
        return df;
    }
}

Related

  1. getZfgcTimeZoneDateFormat(String timezone)
  2. resolveTimeZone(SimpleDateFormat sdf, String timezone)
  3. String2Date(String date, String formatPattern, Locale locale, TimeZone timeZone)
  4. string2Timezone(String srcFormater, String srcDateTime, String dstFormater, String dstTimeZoneId)
  5. toAPITimeString(Date date, String format, String timeZone)