Fetching the current day, month, and year

Let's see how to get just one piece of information from Calendar class. Let's see whether it is actually set to the value of today. Let's print the day, month, and year on three separate println lines to keep things simple. To access the current day, month, and year, we'll need to get those fields from the Calendar object now. If our Calendar object represents a specific moment in time, it should have fields for day, month, and year, right? Well, if we open up our autocomplete option, we can take a look at all the fields and methods available to us, exposed by our Calendar object as shown in the following screenshot:

We're not going to find an easily accessible day, month, and year field, and this ...

Get Java Programming for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.