O'Reilly logo

Java Programming for Beginners by Mark Lassoff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required