Locale specific Formatting Date

Locale can be used to create locale specific formatting over a pattern in SimpleDateFormat class. See the following example of using locale specific SimpleDateFormat class.

Example

Open Compiler

importjava.text.ParseException;importjava.text.SimpleDateFormat;importjava.util.Date;importjava.util.Locale;publicclassI18NTester{publicstaticvoidmain(String[] args)throwsParseException{Locale locale =newLocale("da","DK");String pattern ="EEEEE MMMMM yyyy";SimpleDateFormat simpleDateFormat =newSimpleDateFormat(pattern);Date date =newDate();System.out.println(date);System.out.println(simpleDateFormat.format(date));

      simpleDateFormat =newSimpleDateFormat(pattern,locale);System.out.println(simpleDateFormat.format(date));}}

Output

It will print the following result.

Fri Jun 07 15:02:27 IST 2024
Friday June 2024
fredag juni 2024

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *