Display Date Time in dd MMM yyyy hh:mm:ss zzz 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("dd MMM yyyy hh:mm:ss zzz");

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("dd MMM yyyy hh:mm:ss zzz");
      System.out.println("Date: "+dateFormat.format(dt));
   }
}

Output

Date: 22 Nov 2018 07:53:58 UTC
raja
Published on 19-Dec-2018 05:30:16
Advertisements