Here you can find the source of format(final Date date)
public static String format(final Date date)
//package com.java2s; //License from project: Apache License import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String FORMAT_PATTERN = "yyyy-MM-dd kk:mm:ss.SSS"; public static String format(final Date date) { String milliseconds = new SimpleDateFormat(FORMAT_PATTERN).format(date); if (date instanceof Timestamp) { Timestamp timestamp = (Timestamp) date; final int nanos = timestamp.getNanos(); int microseconds = nanos / 1000; milliseconds = milliseconds.substring(0, milliseconds.indexOf(".") + 1) + String.format("%06d", microseconds); }/* ww w. j ava 2 s. co m*/ return milliseconds; } }