- 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
Format date with DateFormat.LONG in Java
DateFormat.LONG is a constant for long style pattern.
Firstly, we will create date object −
Date dt = new Date(); DateFormat dateFormat;
Let us format date for different locale with DateFormat.LONG −
// ITALY dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.ITALY); // CANADA dateFormat = DateFormat.getDateInstance(DateFormat. LONG, Locale.CANADA);
The following is an example −
Example
import java.text.DateFormat; import java.util.Date; import java.util.Locale; public class Demo { public static void main(String args[]) { Date dt = new Date(); DateFormat dateFormat; // Date Format LONG constant dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRENCH); System.out.println("Locale FRENCH = " + dateFormat.format(dt)); dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.GERMANY); System.out.println("Locale GERMANY = " + dateFormat.format(dt)); dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.CANADA); System.out.println("Locale CANADA = " + dateFormat.format(dt)); dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.ITALY); System.out.println("Locale ITALY = " + dateFormat.format(dt)); } }
Output
Locale FRENCH = 22 novembre 2018 Locale GERMANY = 22. November 2018 Locale CANADA = November 22, 2018 Locale ITALY = 22 novembre 2018
Advertisements