Java Time related content learning (6) Locale Introduction

Source: Internet
Author: User
Tags final locale

This chapter describes locale.

1 Locale Introduction

Locale says the region. Each of the locale objects represents a specific geographical, political and cultural area.

This is often used when manipulating dates, calendar, and other objects that represent date/time, because different regions have different time representations.

Here are 3 common ways to create locale objects.

1 Get the default locale

How to use:

 Locale Locale = Locale.getdefault ()

2 static objects that use locale directly

The following static objects are available in the

public static final Locale CANADA public static final
Locale Canada_french public
static final Locale
Blic static final Locale Chinese public
static final Locale 中文版 public
static final Locale FRANCE public
s Tatic final Locale FRENCH public static
final Locale GERMAN public
static final Locale GERMANY public
static F Inal Locale Italian public static
final Locale ITALY public
static final Locale JAPAN public
static final L Ocale Japanese public static
final Locale KOREA public static
final Locale Korean public
static final local e PRC public
static final Locale ROOT public
static final Locale Simplified_chinese public
static final Loc Ale TAIWAN public static
final Locale Traditional_chinese public static
final Locale UK public
static FINA L Locale US

How to use: The following locale object corresponds to "China (mainland)"

Locale Locale = Locale.simplified_chinese

3 creating locale objects with locale constructors

There are 3 constructors for locale. As follows:

Locale (String language) Locale (string language, String country) Locale (string language, String country, string variant)

How to use:

Locale local = new Locale ("en", "CN");

The locale class supports a great number of countries and regions. We can view all the areas supported by locale in the following ways:

locale[] ls = locale.getavailablelocales ();

for (Locale locale:ls) {System.out.println ("Locale:" +locale);}

Enter the results as follows:

All locales:ja_jp, Es_pe, en, JA_JP_JP, Es_pa, Sr_ba, MK, ES_GT, Ar_ae, No_no, Sq_al, BG, Ar_iq, Ar_ye, Hu, Pt_pt, El_cy, Ar_qa, MK_MK, SV, De_ch, en_US, Fi_fi, is, CS, EN_MT, Sl_si, Sk_sk, it, TR_TR,

En, Th, Ar_sa, no, EN_GB, Sr_cs, lt, Ro, En_nz, No_no_ny, Lt_lt, Es_ni, NL, Ga_ie, Fr_be, Es_es, ar_lb, Ko, Fr_ca, Et_ee, AR_KW, Sr_rs, Es_us, Es_mx, AR_SD, in_id, Ru, LV, Es_uy, LV_LV, IW, Pt_br, Ar_sy,

HR, ET, ES_DO, Fr_ch, hi_in, Es_ve, Ar_bh, en_ph, Ar_tn, FI, De_at, es, Nl_nl, Es_ec, ZH_TW, Ar_jo, be, is_is, Es_co, Es_c R, ES_CL, Ar_eg, En_za, th_th, El_gr, IT_IT, CA, Hu_hu, FR, En_ie, Uk_ua, PL_PL,

Fr_lu, Nl_be, en_in, Ca_es, Ar_ma, Es_bo, En_au, Sr, Zh_sg, PT, UK, ES_SV, Ru_ru, Ko_kr, VI, Ar_dz, VI_VN, Sr_me, Sq, ar_l Y, AR, ZH_CN, be_by, Zh_hk, JA, Iw_il, BG_BG, in, MT_MT, Es_py, SL, FR_FR,

Cs_cz, It_ch, Ro_ro, ES_PR, En_ca, De_de, GA, De_lu, DE, Es_ar, SK, Ms_my, hr_hr, En_sg, DA, MT, PL, Ar_om, tr, th_th_th, El, MS, Sv_se, DA_DK, Es_hn

Here are two examples of how to use them to create locale objects: For example, the first output is "JA_JP".

Among them, JA stands for "language", this refers to Japanese, "JP" on behalf of the country, this refers to Japan. We can create "language is Japanese, country is Japanese locale object" through the following methods.

Locale Locale = new Locale ("Ja", "JP");

For example, the third output is "en".

Where en stands for "language", this refers to English. We can create "locale objects with language in English" by using the following methods.

Locale Locale = new Locale ("en");

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.