Welcome to Kode Java

Kode Java website provides beginners to Java programming some examples to use the Java API (Application Programming Interface) to develop applications. Learning from some examples will hopefully decrease the time required to learn Java.

In this website you will find a lot of examples which grouped by the Java API package. You can easily find a solution to your problem. To help you learn more we have also setup a discussion forums where everyone can share their Java knowledge.

Enjoy your study, come and visit the site regularly to find more and more examples of Java code.

--
I Wayan Saryada
Kode Java Webmaster

Java programmers recommend using Java Hosting for your scripts and JSP based websites to reach the full potential of your site and not experience any errors.

How do I format date using a locale based format?

The code below demonstrate how to format date information for a specific Locale. In the example utilize the java.text.SimpleDateFormat class.

package org.kodejava.example.text;

import java.util.Locale;
import java.util.Date;
import java.text.SimpleDateFormat;

public class FormatDateLocale {
    public static void main(String[] args) {
        //
        // Defines an array of Locale we are going to use for formatting date
        // information.
        //
        Locale[] locales = new Locale[] {
                Locale.JAPAN,
                Locale.CHINA,
                Locale.KOREA,
                Locale.TAIWAN,
                Locale.ITALY,
                Locale.FRANCE,
                Locale.GERMAN
        };

        // Get an instance of current date time
        Date today = new Date();

        //
        // Iterates the entire Locale defined above and create a long formatted
        // date using the SimpleDateFormat.getDateInstance() with the format, the
        // Locale and the date information.
        //
        for (Locale locale : locales) {
            System.out.println("Date format in " 
                + locale.getDisplayName() 
                + " = " 
                + SimpleDateFormat.getDateInstance(
                      SimpleDateFormat.LONG, locale).format(today).toUpperCase());
        }
    }
}

The result of our code are:

Date format in Japanese (Japan) = 2009/01/04
Date format in Chinese (China) = 2009年1月4日
Date format in Korean (South Korea) = 2009년 1월 4일 (일)
Date format in Chinese (Taiwan) = 2009年1月4日
Date format in Italian (Italy) = 4 GENNAIO 2009
Date format in French (France) = 4 JANVIER 2009
Date format in German = 4. JANUAR 2009
Can't find what you are looking for? Join our FORUMS and ask some questions!
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats