fork download
  1. import java.time.DayOfWeek;
  2. import java.time.Month;
  3. import java.time.ZoneId;
  4. import java.time.ZonedDateTime;
  5. import java.time.format.TextStyle;
  6. import java.util.Locale;
  7.  
  8. public class Main {
  9. public static void main(String[] args) {
  10. // Specify the applicable ZoneId e.g.
  11. // ZonedDateTime.now(ZoneId.of("Asia/Kolkata"))
  12. // to get the current date-time in that timezone
  13. ZonedDateTime now = ZonedDateTime.now();
  14.  
  15. DayOfWeek dow = now.getDayOfWeek();
  16. System.out.println(dow);
  17.  
  18. int weekDayNum = dow.getValue();
  19. System.out.println(weekDayNum);
  20.  
  21. String weekDayName = dow.getDisplayName(TextStyle.FULL, Locale.ENGLISH);
  22. System.out.println(weekDayName);
  23.  
  24. int year = now.getYear();
  25. System.out.println(year);
  26.  
  27. Month month = now.getMonth();
  28. System.out.println(month);
  29.  
  30. int monthValue = month.getValue();
  31. System.out.println(monthValue);
  32.  
  33. int dayOfMonth = now.getDayOfMonth();
  34. System.out.println(dayOfMonth);
  35.  
  36. int dayOfYear = now.getDayOfYear();
  37. System.out.println(dayOfYear);
  38. }
  39. }
Success #stdin #stdout 0.15s 52764KB
stdin
Standard input is empty
stdout
MONDAY
1
Monday
2021
NOVEMBER
11
1
305