Home Java Javadate Formatting Date for a Locale Example
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Formatting Date for a Locale Example

Advertisement
This example shows how to format Date using SimpleDateFormat class. In this program we are format date for different locales.

Formatting Date for a Locale Example

     

This example shows how to format Date using SimpleDateFormat class. In this program we are format date for different locales.

Description of the code :

SimpleDateFormat() : SimpleDateFormat class use for formatting and parsing dates. It allows for formatting date into text , parsing text into date and normalization.

format() : This method is used for format Date class object into date / time and appends the it into the StringBuffer.

LocaleFormat.java
import java.text.*;
import java.util.*;

public class LocaleFormat {
    public static void main(String args[]) {
        Locale[] locales = {Locale.UK, Locale.FRANCE, Locale.ITALIAN};
        Date date = new Date();
        String s;
      for (int i = 0; i < locales.length; i++) {
          s = SimpleDateFormat.getDateInstance(SimpleDateFormat.FULL, 
                                               locales[i]).format(date);
         System.out.println(locales[i].getDisplayLanguage() + "\t : " + s);
        }
    }
}


When you run this application it will display message as shown below:

English : Saturday, 11 October 2008 French : samedi 11 octobre 2008

Italian : sabato 11 ottobre 2008

Download code
Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 13, 2008

Ask Questions?    Discuss: Formatting Date for a Locale Example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Preetam Sahu
February 9, 2012
Dateformate

how to create india date formate in hindi
DMCA.com