java tutorial - Internationalizing Date (I18N with Date) - java programming - learn java - java basics - java for beginners
- Internationalize the date by using the getDateInstance() method of the DateFormat class.
- It receives the locale object as a parameter and returns the instance of the DateFormat class.
Methods of DateFormat class for internationalizing date
- There are many methods of the DateFormat class.The two methods of the DateFormat class for internationalizing the dates.
- public static DateFormat getDateInstance(int style, Locale locale) returns the instance of the DateFormat class for the specified style and locale. The style can be DEFAULT, SHORT, LONG etc.
- public String format(Date date) returns the formatted and localized date as a string.
- In this example, we are displaying the date according to the different locale such as UK, US, FRANCE etc.
- For this purpose we have created the printDate() method that receives Locale object as an instance.
- The format() method of the DateFormat class receives the Date object and returns the formatted and localized date as a string.