java.Util package, exists an abstract class called the
This class allows has the following roles:
- Conversion between a specific instant of time and a set of fields of such as:
- HOUR etc.
- Manipulating those Calender fields.
As an abstract class, the Calender class cannot be instantiated directly.
Instead, it provides us with a method called
getInstance() that gets for us the Calender object using the default timeone and locale.
Let’s look at examples to see how to use Calender class.
Get current year, month and day:
// Get Year, Month and Day From java.util.Calendar final Calendar c = Calendar.getInstance(); myYear = c.get(Calendar.YEAR); myMonth = c.get(Calendar.MONTH); myDay = c.get(Calendar.DAY_OF_MONTH);
In android these can then be passed to DatePickerDialog to be shown.
new DatePickerDialog(this, myDateSetListener, myYear,myMonth, myDay);
See how we do that in here.