- Java Programming Examples
- Example - Home
- Example - Environment
- Example - Strings
- Example - Arrays
- Example - Date & Time
- Example - Methods
- Example - Files
- Example - Directories
- Example - Exceptions
- Example - Data Structure
- Example - Collections
- Example - Networking
- Example - Threading
- Example - Applets
- Example - Simple GUI
- Example - JDBC
- Example - Regular Exp
- Example - Apache PDF Box
- Example - Apache POI PPT
- Example - Apache POI Excel
- Example - Apache POI Word
- Example - OpenCV
- Example - Apache Tika
- Example - iText
- Java Tutorial
- Java - Tutorial
- Java Useful Resources
- Java - Quick Guide
- Java - Useful Resources
How to display time in different country's format in Java
Problem Description
How to display time in different country's format?
Solution
Following example uses Locale class & DateFormat class to display date in different Country's format.
import java.text.DateFormat; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Date d1 = new Date(); System.out.println("today is "+ d1.toString()); Locale locItalian = new Locale("it","ch"); DateFormat df = DateFormat.getDateInstance (DateFormat.FULL, locItalian); System.out.println("today is in Italian Language in Switzerland Format : "+ df.format(d1)); } }
Result
The above code sample will produce the following result.
today is Mon Jun 22 02:37:06 IST 2009 today is in Italian Language in Switzerland Format : sabato, 22. febbraio 2014
java_date_time.htm
Advertisements