Java Internalization - Formatting Date


Advertisements

DateFormat class provides various formats to format the date. Following is list of some of the formats.

  • DateFormat.DEFAULT

  • DateFormat.SHORT

  • DateFormat.MEDIUM

  • DateFormat.LONG

  • DateFormat.FULL

In following example we'll show how to use different formats.

IOTester.java

import java.text.DateFormat;
import java.util.Date;

public class I18NTester {
   public static void main(String[] args) {
   
      DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT);

      System.out.println(dateFormat.format(new Date()));

      dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);

      System.out.println(dateFormat.format(new Date()));

      dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);

      System.out.println(dateFormat.format(new Date()));

      dateFormat = DateFormat.getDateInstance(DateFormat.LONG);

      System.out.println(dateFormat.format(new Date()));

      dateFormat = DateFormat.getDateInstance(DateFormat.FULL);

      System.out.println(dateFormat.format(new Date()));
  
  
   }
}

Output

It will print the following result.

Nov 29, 2017
11/29/17
Nov 29, 2017
November 29, 2017
Wednesday, November 29, 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