Get Time From java.util.Date in Java
Description
The following code shows how to get Time From java.util.Date.
Example
//from ww w. j a va2s . c o m
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static String getTimeFromDate (Date date) throws ParseException {
DateFormat formatter = new SimpleDateFormat("HH:mm:ss.SSS");
return formatter.format(date);
}
public static void main(String[] argv) throws ParseException {
System.out.println(getTimeFromDate(new Date()));
}
}
The code above generates the following result.