want current date and time in “dd/MM/yyyy HH:mm:ss.SS” format

后端 未结 10 1414
南旧
南旧 2020-11-22 01:31

I am using following code to get date in \"dd/MM/yyyy HH:mm:ss.SS\" format.

    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import          


        
10条回答
  •  日久生厌
    2020-11-22 02:21

    Here's a simple snippet working in Java 8 and using the "new" date and time API LocalDateTime:

    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss.SS");
    LocalDateTime now = LocalDateTime.now();
    System.out.println(dtf.format(now)); 
    

提交回复
热议问题