Java TimeZone Format createDateFormatsForLocaleAndTimeZone(Locale locale, TimeZone timeZone)

Here you can find the source of createDateFormatsForLocaleAndTimeZone(Locale locale, TimeZone timeZone)

Description

Build an array of DateFormats that are commonly used for this locale and timezone.

License

Open Source License

Declaration

static DateFormat[] createDateFormatsForLocaleAndTimeZone(Locale locale, TimeZone timeZone) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;

import java.util.ArrayList;

import java.util.List;
import java.util.Locale;

import java.util.TimeZone;

public class Main {
    /**//from  w ww . j  a v a2 s  .  c  o  m
     * Build an array of DateFormats that are commonly used for this locale
     * and timezone.
     */
    static DateFormat[] createDateFormatsForLocaleAndTimeZone(Locale locale, TimeZone timeZone) {
        List<DateFormat> formats = new ArrayList<DateFormat>();

        addDateTimeFormatsToList(locale, timeZone, formats);
        addDateFormatsToList(locale, timeZone, formats);

        return formats.toArray(new DateFormat[formats.size()]);
    }

    static void addDateTimeFormatsToList(Locale locale, TimeZone timeZone, List<DateFormat> formats) {
        for (int dateStyle = DateFormat.FULL; dateStyle <= DateFormat.SHORT; dateStyle++) {
            for (int timeStyle = DateFormat.FULL; timeStyle <= DateFormat.SHORT; timeStyle++) {
                DateFormat df = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
                if (timeZone != null) {
                    df.setTimeZone(timeZone);
                }
                formats.add(df);
            }
        }
    }

    static void addDateFormatsToList(Locale locale, TimeZone timeZone, List<DateFormat> formats) {
        for (int dateStyle = DateFormat.FULL; dateStyle <= DateFormat.SHORT; dateStyle++) {
            DateFormat df = DateFormat.getDateInstance(dateStyle, locale);
            df.setTimeZone(timeZone);
            formats.add(df);
        }
    }
}

Related

  1. addDateFormatsToList(Locale locale, TimeZone timeZone, List formats)
  2. createDateFormat(String format, TimeZone tz)
  3. createDateFormat(String pattern, TimeZone timeZone)
  4. createDateFormat(TimeZone timezone)
  5. formatISO8601TimeZone(TimeZone timeZone, boolean extended)
  6. formatOffset(TimeZone zone)
  7. formatTimeZoneOffset(TimeZone timeZone)
  8. getCalendar(String dateString, String dateTimeFormat, String timeZoneName)