Convert Millisecond value To Date in Java


import java.text.SimpleDateFormat;
import java.util.Date;
public class ConvertMillisecondToDate {
public static void main(String[] args) throws Exception {
SimpleDateFormat sdf = 
                    new SimpleDateFormat( "dd-MM-yyyy hh:mm:ss.SSS");
// Get current time in milliseconds
Long milliSec = System.currentTimeMillis();
                System.out.println("MilliSec : "+ milliSec);
Date date = new Date(milliSec);
System.out.println("Date : "+ sdf.format(date));
}
}


Output:

MilliSec : 1328990835987
Date: 12-02-2012 01:37:15.987



Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email