- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Locale-specific formatting in Java
For locale-specific formatting, firstly import the following packages.
import java.util.Calendar; import java.util.Formatter; import java.util.Locale;
Create a Formatter and Calendar object −
Formatter f = new Formatter(); Calendar c = Calendar.getInstance();
We are formatting for different Locales −
f.format(Locale.TAIWAN, "Locale.TAIWAN: %tc
", c); f.format(Locale.ITALY, "Locale.ITALY: %tc
", c);
The following is an example −
Example
import java.util.Calendar; import java.util.Formatter; import java.util.Locale; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar c = Calendar.getInstance(); f.format(Locale.TAIWAN, "Locale.TAIWAN: %tc
", c); f.format(Locale.ITALY, "Locale.ITALY: %tc
", c); f.format(Locale.FRENCH, "Locale.FRENCH: %tc
", c); f.format(Locale.GERMANY, "Locale.GERMANY: %tc
", c); System.out.println(f); } }
Output
Locale.TAIWAN: 星期日十一月 25 14:36:20 UTC 2018 Locale.ITALY: dom nov 25 14:36:20 UTC 2018 Locale.FRENCH: dim. nov. 25 14:36:20 UTC 2018 Locale.GERMANY: So Nov 25 14:36:20 UTC 2018
- Related Articles
- Locale-specific morning/afternoon indicator in Java
- Importance of a Locale class in Java?
- What is a Locale class in Java?
- String Formatting in Java using %
- Change date formatting symbols in Java
- Formatting Minute in m format in Java
- Formatting day in d format in Java
- Formatting day in dd format in Java
- What is Common Locale Data Repository (CLDR) in Java 9?\n
- Formatting day of week using SimpleDateFormat in Java
- Locale Environment Variables in Linux
- Formatting day of week in EEEE format in Java
- Formatting a Negative Number Output with Parentheses in Java
- How to use formatting with printf() correctly in Java?
- Java Program to get display name for Day of Week in different locale

Advertisements