Android Calendar: First And Last Day Of Week -> Zero Month
Solution 1:
Field number for
get
andset
indicating the month. This is a calendar-specific value. The first month of the year in the Gregorian and Julian calendars isJANUARY
which is 0; the last depends on the number of months in a year.
Thus the first month (January) has a MONTH
value of 0
, and not 1
(as you'd expect).
There's a much better solution though: use a DateFormat
or SimpleDateFormat
to format dates as text. That way, you simply don't have to worry about this and let the DateFormat
take care of it. For example:
DateFormatmyFormat=newSimpleDateFormat("dd.MM.yyyy");
MyTextView.setText(
myFormat.format(calendarFirstDay.getTime()) + " - " +
myFormat.format(calendarLastDay.getTime())
);
Solution 2:
As stated in
http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#set(int,%20int,%20int)
if you use this method, January will be 0 and Decmember will be 11, so you should just add 1 to your month.
EDIT: You are using the get
method but it's probably 0-based, too.
Post a Comment for "Android Calendar: First And Last Day Of Week -> Zero Month"