下面的代码为我提供了当前时间。但这并不能说明毫秒。
public static String getCurrentTimeStamp() {
    SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//dd/MM/yyyy
    Date now = new Date();
    String strDate = sdfDate.format(now);
    return strDate;
}我有一个格式YYYY-MM-DD HH:MM:SS ( 2009-09-22 16:47:08 )。
 YYYY-MM-DD HH:MM:SS.MS ( 2009-09-22 16:47:08.128 ,其中128是毫秒)的格式检索当前时间。
 SimpleTextFormat可以正常工作。在这里,最小的时间单位是秒,但是如何获得毫秒呢?
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");Java 一线
public String getCurrentTimeStamp() {
    return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
}以 JDK8 风格
public String getCurrentLocalDateTimeStamp() {
    return LocalDateTime.now()
       .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"));
}您只需在日期格式字符串中添加毫秒字段:
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");SimpleDateFormat 的API 文档详细描述了格式字符串。