”;
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
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class I18NTester { public static void main(String[] args) throws ParseException { Locale locale = new Locale("da", "DK"); String pattern = "EEEEE MMMMM yyyy"; SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); Date date = new Date(); System.out.println(date); System.out.println(simpleDateFormat.format(date)); simpleDateFormat = new SimpleDateFormat(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
Advertisements
”;