Example usage for java.util Locale Locale

List of usage examples for java.util Locale Locale

Introduction

In this page you can find the example usage for java.util Locale Locale.

Prototype

public Locale(String language, String country) 

Source Link

Document

Construct a locale from language and country.

Usage

From source file:Main.java

public static void main(String[] args) {
    DateFormatSymbols symbols = new DateFormatSymbols(new Locale("en", "US"));
    String[] defaultDays = symbols.getShortWeekdays();

    for (int i = 0; i < defaultDays.length; i++) {
        System.out.print(defaultDays[i] + "  ");
    }/*from  ww  w  .  j  a v a2s . c om*/
    System.out.println();

    String[] capitalDays = { "", "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
    symbols.setShortWeekdays(capitalDays);

    String[] modifiedDays = symbols.getShortWeekdays();
    for (int i = 0; i < modifiedDays.length; i++) {
        System.out.println(modifiedDays[i] + "  ");
    }

    SimpleDateFormat formatter = new SimpleDateFormat("E", symbols);
    Date today = new Date();
    String result = formatter.format(today);
    System.out.println(result);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Locale myLocale;/*  ww w  .j  a  v  a2 s. c o  m*/
    if (argv.length < 2)
        myLocale = Locale.getDefault();
    else
        myLocale = new Locale(argv[0], argv[1]);
    ComponentOrientation ce = ComponentOrientation.getOrientation(myLocale);
    System.out.println("Is horizontal? " + ce.isHorizontal());
    System.out.println("Is left to right? " + ce.isLeftToRight());
}

From source file:Main.java

public static void main(String args[]) {

    // create default time zone object
    TimeZone timezone = TimeZone.getTimeZone("Europe/Paris");

    // create locale
    Locale locale = new Locale("CHINESE", "CHINA");

    // get display name for specific locale
    String disname = timezone.getDisplayName(locale);

    // checking display name         
    System.out.println("Display name is :" + disname);
}

From source file:HelloResourceBundleExample.java

  public static void main(String [] argv) {
  try {/* w  w w  .  ja  v  a2 s  .co  m*/
    Locale frenchLocale = new Locale("fr", "FR");
    ResourceBundle rb = ResourceBundle.getBundle("HelloResourceBundle", frenchLocale);

    System.out.println(rb.getString("Hello"));
    System.out.println(rb.getString("Goodbye"));

  } catch (MissingResourceException mre) {
    mre.printStackTrace();
  }
}

From source file:Main.java

public static void main(String args[]) {

    // create default time zone object
    TimeZone timezone = TimeZone.getTimeZone("US");

    // get display name for specific locale
    String disname = timezone.getDisplayName(true, 1, new Locale("EN", "US"));

    // checking display name         
    System.out.println("Display name is :" + disname);
}

From source file:Main.java

/** Typical main method ("main program") declaration */
public static void main(String[] av) {

    Locale l1 = new Locale("en", "US"), l2 = new Locale("es", "ES");

    // Create a Date object for May 5, 1986
    Calendar c = Calendar.getInstance();
    c.set(1986, 04, 05); // May 5, 1986
    Date d1 = c.getTime();//from  w  w  w  . j a va  2s. c o  m

    // Create a Date object for today.
    Date d2 = new Date(); // today

    DateFormat df_us = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, l1),
            df_sp = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, l2);
    System.out.println("Date d1 for US is " + df_us.format(d1));
    System.out.println("Date d1 for Spain is " + df_sp.format(d1));
    System.out.println("Date d2 is " + df_us.format(d2));
}

From source file:Main.java

public static void main(String[] args) {
        ResourceBundle bundle = ResourceBundle.getBundle("MessagesBundle", Locale.UK);
        System.out.println("Message in " + Locale.UK + ": " + bundle.getString("greeting"));

        Locale.setDefault(new Locale("in", "ID"));
        bundle = ResourceBundle.getBundle("MessagesBundle");
        System.out.println("Message in " + Locale.getDefault() + ": " + bundle.getString("greeting"));
    }/*  www.  j a  v  a  2 s  . c  om*/

From source file:MainClass.java

public static void main(String[] args) {
    ArrayList list = new ArrayList();
    list.add("\u00e4pple");
    list.add("banan");
    list.add("p\u00e4ron");
    list.add("orange");

    // Obtain a Swedish collator
    Collator collate = Collator.getInstance(new Locale("sv", ""));
    Collections.sort(list, collate);

    for (int i = 0; i < list.size(); i++) {
        System.out.println(list.get(i));
    }/*from   w w  w. j a  v a  2s  . c  om*/
}

From source file:Main.java

public static void main(String[] args) {
    Currency currency = Currency.getInstance(Locale.JAPAN);
    System.out.println("Currency.getSymbol() = " + currency.getSymbol());

    currency = Currency.getInstance(Locale.UK);
    System.out.println("Currency.getSymbol() = " + currency.getSymbol());

    currency = Currency.getInstance(Locale.US);
    System.out.println("Currency.getSymbol() = " + currency.getSymbol());

    currency = Currency.getInstance(new Locale("in", "ID"));
    System.out.println("Currency.getSymbol() = " + currency.getSymbol());
}

From source file:Main.java

public static void main(String[] args) {
    Date now = new Date();

    DateFormat defaultFormat = DateFormat.getDateTimeInstance();
    String defaultString = defaultFormat.format(now);
    System.out.println("Default : " + defaultString);

    DateFormat antarcticaFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,
            new Locale("en", "AQ"));
    String antarcticaString = antarcticaFormat.format(now);
    System.out.println("Antarctica: " + antarcticaString);
}