Internationalization in NetBeans

Introduction

This article explains Internationalization. Today every individual on this planet is using the internet. Various people use various languages to speak and understand, not every individual will be able to understand or communicate in the same language. So the concept of Internationalization was adapted to abolish the issues of languages. Internationalization is also abbreviated as I18N because there are exactly 18 characters in between "I" and "N".  Today we will discuss a small part of Internationalization using the DateFormat class.

Introduction to Locale class

This Locale class gathers Locale specific information like:

  • Country
  • Language
  • Varient

To specify the language and country as user preferences, two letter codes are used. Language code contains small letters and Country code contains capital letters.

Constructors of Locale class

The constructors of the Locale class are:

  • public Locale(String language code)
  • public Locale(String language code,String country code)
  • public Locale(String language code,String country code,String varient)

Introduction to DateFormat class

The DateFormat class formats dates and times. The information of both date and time are accessed by this class.

DateFormat class Methods

The Methods of the DateFormat class are:

  • getDateInstance(): It returns a Locale specific DateFormat object that is basically used for date formatting.

            Syntax: public static DateFormat getDateInstance(int style Locale l);

  • getTimeInstance(): It returns a Locale specific DateFormat object that is basically used for time formatting.

            Syntax: public static DateFormat getTimeInstance(int style.Locale l);

To specify the style, static final content is defined in the DateFormat class.

Example: DateFormat.Short, DateFormat.LONG

  • format(): It is used to convert a date into a string.

            Syntax: public String format(Date d);

Date is the predefined class, it belongs to java.util package, using this class object we obtain the current date and time.

Source code

fig3.4.jpg

Run the Source code

fig3.5.jpg

Output

The output screenshots are:

fig3.1.jpg

Enter the Language and Country in the window shown after running the source code and click on the Format button. The following has the language "en" (English) and the country "IN" (India).

fig3.2.jpg

The following is a screenshot with language the "hi" (Hindi) and the country "IN".

fig3.3.jpg

 


Similar Articles