Program to convert Milliseconds to Date Format in Java

Java 8Object Oriented ProgrammingProgramming

Let us first declare and initialize milliseconds value variable −

long milliSeconds = 656478;

Now, convert Milliseconds to Date format −

DateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss:SSS Z");
Date date = new Date(milliSeconds);

Following is the program to convert Milliseconds to Date Format in Java −

Example

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Demo {
   public static void main(String args[]) {
      long milliSeconds = 656478;
      DateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss:SSS Z");
      Date date = new Date(milliSeconds);
      System.out.println(dateFormat.format(date));
   }
}

Output

01 Jan 1970 00:10:56:478 +0000
raja
Published on 23-Sep-2019 13:54:38
Advertisements