Unix date format in Java

Java 8Object Oriented ProgrammingProgramming

Use the ‘c’ date conversion character to display UNIX date format in Java.

System.out.printf("Unix date format: %tc",d);

Above, d is a date object.

Date d = new Date();


 Live Demo

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class Demo {
   public static void main(String[] args) throws Exception {
      Date d = new Date();
      System.out.printf("Unix date format: %tc",d);
      System.out.printf("\nUnix date format: %Tc",d);


Unix date format: Mon Nov 26 12:24:10 UTC 2018
Unix date format: MON NOV 26 12:24:10 UTC 2018
Published on 14-Dec-2018 05:57:42