To print current date and time using Java, you have to import libraries:
import java.time.format.DateTimeFormatter;  
import java.time.LocalDateTime;    
Then to print date and time, you have to write the code given below.
DateTimeFormatter dt = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");  
LocalDateTime now = LocalDateTime.now();  
System.out.println(dt.format(now)); 
Output will be:
2018/04/13 16:18:28