How to get current Day, Month, Year from Date in Java 8 and before? LocalDate vs java.util.Date

In this article, I'll show you how to get the current day, month, year, and dayOfWeek in Java 8 and earlier version e.g. Java 6 and JDK 1.7. Prior to Java 8, you can use the Calendar class to get the various attribute from java.util.Date in Java. The Calendar class provides a get() method which accepts an integer field corresponding to the attribute you want to extract and return the value of the field from given Date, as shown here. You might be wondering, why not use the getMonth() and getYear() method of java.util.Date itself, well, they are deprecated and can be removed in the future version, hence it is not advised to use them. The key point is, using old Date and Calendar API is not easy, it's very difficult to reason and debug code written using Calendar API, as it uses integer value instead of Enum or String. So, when you print e.g. Month, it will print 0 (Zero which may look wrong, but it's the value for January in old Date and Calendar API.
Read more »