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}
1SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
2Date date = new Date();
3System.out.println(formatter.format(date));
4
5// ------------------------
6
7System.out.println(LocalDate.now());
1Calendar calendar = Calendar.getInstance();
2int day = calendar.get(Calendar.DAY_OF_WEEK);
3
4switch (day) {
5 case Calendar.SUNDAY:
6 // Current day is Sunday
7 break;
8 case Calendar.MONDAY:
9 // Current day is Monday
10 break;
11 case Calendar.TUESDAY:
12 // etc.
13 break;
14}