- 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
Advertisements