Java : Date Format Locale and Internationalization


java.text.SimpleDateFormat class is subclass for java.text.DateFormat which use to convert String to Date and Date to different formatted String. DateFormat class supports TimeZone and Locale specific conversions also.

In below example you will see conversion of date to different Internationalization date by using Locale in SimpleDateFormat.

Example

package com.date;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class DateFormatLocaleAndInternationalization {

// Date formats
private static final String MAIN_DATE_FORMAT = "yyyy-MM-dd'T'hh:mm:ss.SSS'Z'";

public static void main(String[] args) {

Date date = new Date();
System.out.println("Date:" + date);

SimpleDateFormat formatter = new SimpleDateFormat(MAIN_DATE_FORMAT, Locale.CANADA);
System.out.println("CANADA DATE :" + formatter.format(date));

formatter = new SimpleDateFormat(MAIN_DATE_FORMAT, Locale.CANADA_FRENCH);
System.out.println("CANADA FRENCH DATE :" + formatter.format(date));

formatter = new SimpleDateFormat(MAIN_DATE_FORMAT, Locale.GERMANY);
System.out.println("GERMANY :" + formatter.format(date));

formatter = new SimpleDateFormat(MAIN_DATE_FORMAT, Locale.CHINESE);
System.out.println("CHINESE DATE :" + formatter.format(date));
formatter = new SimpleDateFormat(MAIN_DATE_FORMAT, Locale.ITALIAN);
System.out.println("ITALIAN :" + formatter.format(date));

formatter = new SimpleDateFormat(MAIN_DATE_FORMAT, Locale.TAIWAN);
System.out.println("TAIWAN DATE :" + formatter.format(date));

	}

}

Output


Date:Mon Jul 30 12:01:13 PDT 2018
CANADA DATE :2018-07-30T12:01:13.909Z
CANADA FRENCH DATE :2018-07-30T12:01:13.909Z
GERMANY :2018-07-30T12:01:13.909Z
CHINESE DATE :2018-07-30T12:01:13.909Z
ITALIAN :2018-07-30T12:01:13.909Z
TAIWAN DATE :2018-07-30T12:01:13.909Z
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s