1import java.time.format.DateTimeFormatter;
2import java.time.LocalDateTime;
3public class CurrentDateTimeExample1 {
4 public static void main(String[] args) {
5 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
6 LocalDateTime now = LocalDateTime.now();
7 System.out.println(dtf.format(now));
8 }
9}
1// get current date and timein java using Calendar.getTime() method
2import java.util.Calendar;
3import java.util.Date;
4public class UsingCalendarClass
5{
6 public static void main(String[] args)
7 {
8 Date date = Calendar.getInstance().getTime();
9 System.out.println(date);
10 }
11}