Get all attributes from a Calendar


import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    public static void main(String[] a) {
        Date timeNow = new Date();
        Calendar calendar = new GregorianCalendar();
        
        calendar.setTime(timeNow);
        System.out.println("ERA: " + calendar.get(Calendar.ERA));
        System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
        System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
        System.out.println("WEEK_OF_YEAR: "+ calendar.get(Calendar.WEEK_OF_YEAR));
        System.out.println("WEEK_OF_MONTH: "+ calendar.get(Calendar.WEEK_OF_MONTH));
        System.out.println("DATE: " + calendar.get(Calendar.DATE));
        System.out.println("DAY_OF_MONTH: "+ calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
        System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
        System.out.println("DAY_OF_WEEK_IN_MONTH: "+ calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
        System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
        System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
        System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
        System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
        System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
        System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
        System.out.println("ZONE_OFFSET: "+ (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)));
        System.out.println("DST_OFFSET: "+ (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000)));
    }
}

Output:


ERA: 1
YEAR: 2012
MONTH: 8
WEEK_OF_YEAR: 36
WEEK_OF_MONTH: 2
DATE: 7
DAY_OF_MONTH: 7
DAY_OF_YEAR: 251
DAY_OF_WEEK: 6
DAY_OF_WEEK_IN_MONTH: 1
AM_PM: 0
HOUR: 10
HOUR_OF_DAY: 10
MINUTE: 7
SECOND: 23
MILLISECOND: 643
ZONE_OFFSET: -8
DST_OFFSET: 1
Home 
  Java Book 
    Runnable examples  

Date Get:
  1. Day of Week
  2. Number of days in a month
  3. Month of year
  4. Current month name
  5. Full date time
  6. Get all attributes from a Calendar
  7. Get year, month, day, minute, hour, second, milli second from java.util.Date through Calendar
  8. Get age from a birthday date
  9. Get Monday
  10. Get next Sunday
  11. Get today's date
  12. Get the last day of a month
  13. Get date of yesterday
  14. Get Day-of-Week for a Particular Date
  15. Get date of last week
  16. Get date of last month
  17. Get last Date of This Month
  18. Get Month in a leap year
  19. Get start of a month
  20. Get the end of a month
  21. Get noon of a day
  22. Get days since a date
  23. Get TimeZone
  24. Get Last day fo previous Month
  25. Is an hour between an interval
  26. Is a Year a Leap Year