How do I get date, month, year values from the current date?

Share:

What date, month, year, day-of-week, day-of-month, day-of-year is it today? If we want to answer these question we can use java.util.Calendar and java.util.GregorianCalendar which is the implementation of Calendar abstract class.

These classes can help us to get integer value such as date, month, year from a Date object. Let’s see the example code.

Here is the result of this example:

You might also want to try to use the Joda Time library for this. Here another example for getting information about date and time using Joda: How do I get date / time fields of date in Joda?.

Share: