Display Date in E MMM dd yyyy format in Java

Java 8Object Oriented ProgrammingProgramming

Firstly, import the following Java packages −

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

Now, create objects −

Date dt = new Date();
SimpleDateFormat dateFormat;

Displaying date in the format we want

dateFormat = new SimpleDateFormat("E MMM dd yyyy");

The following is an example −

Example

 Live Demo

import java.text.SimpleDateFormat;
import java.util.Date;
public class Demo {
   public static void main(String args[]) {
      Date dt = new Date();
      SimpleDateFormat dateFormat;
      dateFormat = new SimpleDateFormat("E MMM dd yyyy");
      System.out.println("Date: "+dateFormat.format(dt));
   }
}

Output

Date: Thu Nov 22 2018
raja
Published on 19-Dec-2018 05:37:49
Advertisements