How to get the current time in yyyy-MM-dd HH:mm:Sec.Millisecond format in Java

1 Answer

0 votes
import java.text.SimpleDateFormat;  
import java.util.Date;  

public class MyClass {
    public static void main(String args[]) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        
        String currentTime = sdf.format(new Date());
 
        System.out.println(currentTime);
    }
}
 
 
 
/*
run:
 
2023-11-28 11:09:43.089
 
*/

 



answered Nov 28, 2023 by avibootz

Related questions

1 answer 168 views
1 answer 147 views
1 answer 163 views
1 answer 154 views
1 answer 224 views
...