Java DateFormat getAvailableLocales() Example

DateFormat class getAvailableLocales() method example. This example shows you how to use getAvailableLocales() method.


Syntax is : public static Locale[] getAvailableLocales()
Method returns an array of all locales for which the get*Instance methods of this class can return localized instances. The returned array
represents the union of locales supported by the Java runtime and by installed DateFormatProvider implementations. It must contain at
least a Locale instance equal to Locale.US.

Here is the code.
/**
 * @(#) GetAvailableLocalesDateFormat.java
 * A class representing use of method getAvailableLocales() of DateFormat
class in java.text Package.
 * @Version  12-May-2008
 @author   Rose India Team
 */
import java.util.*;
import java.text.*;

class GetAvailableLocalesDateFormat {

    public static void main(String[] args) {

        // Create new Date object that will be initialized to the current date.
        Date date = new Date();
        System.out.println("Date  by  Date  class    : " + date.toString());

        // Create new DateFormat object that will returns default date/time.
        DateFormat dateFormat = DateFormat.getInstance();

        // getAvailableLocales method call.
        Locale[] locale = dateFormat.getAvailableLocales();
        System.out.println("Available locales for this dateformat : ");
        for (int i = 0; i < locale.length; i++) {
            System.out.println(locale[i]);
        }
    }
}

Output of the program.
 Date  by  Date  class    : Thu Jun 12 18:00:47 GMT+05:30 2008
Available locales for this dateformat :
ja_JP
es_PE
en
ja_JP_JP
es_PA
sr_BA
mk
es_GT
ar_AE
no_NO
---------------------

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US