How to get the current time in YYYY-MM-DD HH:MI:Sec.Millisecond format in Java?

后端 未结 15 2326
不思量自难忘°
不思量自难忘° 2020-11-22 15:05

The code below gives me the current time. But it does not tell anything about milliseconds.

public static String getCurrentTimeStamp() {
    SimpleDateForm         


        
15条回答
  •  轮回少年
    2020-11-22 15:18

    To complement the above answers, here is a small working example of a program that prints the current time and date, including milliseconds.

    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    public class test {
        public static void main(String argv[]){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            Date now = new Date();
            String strDate = sdf.format(now);
            System.out.println(strDate);
        }
    }
    

提交回复
热议问题