The format of the dates differ from one region to another that is why we internationalize the dates.
We can 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.
There are many methods of the DateFormat class. Let's see the two methods of the DateFormat class for internationalizing the dates.
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.
import java.text.DateFormat; import java.util.*; public class InternationalizationDate { static void printDate(Locale locale){ DateFormat formatter=DateFormat.getDateInstance(DateFormat.DEFAULT,locale); Date currentDate=new Date(); String date=formatter.format(currentDate); System.out.println(date+" "+locale); } public static void main(String[] args) { printDate(Locale.UK); printDate(Locale.US); printDate(Locale.FRANCE); } }