Java Internalization - Locale specific Formatting Date


Advertisements

Locale can be used to create locale specific formatting over a pattern in SimpleDateFormat class. See the following example of using locale specific SimpleDateFormat class.

IOTester.java

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

public class I18NTester {
   public static void main(String[] args) throws ParseException {

      Locale locale = new Locale("da", "DK");
      String pattern = "EEEEE MMMMM yyyy";

      SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);

      Date date = new Date();

      System.out.println(date);
      System.out.println(simpleDateFormat.format(date));

      simpleDateFormat = new SimpleDateFormat(pattern,locale);

      System.out.println(simpleDateFormat.format(date));
   }
}

Output

It will print the following result.

Wed Nov 29 17:48:14 IST 2017
Wednesday November 2017
onsdag november 2017
Print

Useful Video Courses


Video

Java Date and Time Online Training

16 Lectures 2 hours

Malhar Lathkar

Video

Java Servlet Online Training

19 Lectures 5 hours

Malhar Lathkar

Video

JavaScript Online Training

25 Lectures 2.5 hours

Anadi Sharma

Video

Java Online Training

Most Popular

126 Lectures 7 hours

Tushar Kale

Video

Java Essential Training

119 Lectures 17.5 hours

Monica Mittal

Video

Java Essentials Online Training

76 Lectures 7 hours

Arnab Chakraborty

Advertisements