DatePickerFragment question


#1

I’m trying the harder challenge and thought I’d use DatePickerFragment as a model. I thought I understood the code, but I’m puzzled by something.

In it we find:

Calendar calendar = Calendar.getInstance();
calendar.setTime(mDate);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);

What is setTime(mDate) doing there? Should we be getting the time from the mDate?

However, later on in the code we find:

mDate = new GregorianCalendar(year, month, day).getTime();

Which I’m interpreting as building up mDate from the revised information. What is getTime() doing there? Wouldnt it be getting the current date and time? Wouldnt we want the date that came along when mDate was entered as an argument?

It’s as if, to me anyway, get/set are reversed.

I tried to read and developers documentation but that didnt help. I’m obviously confused.

Thanks


#2
That means set the calendar's time based on the time stamp stored by mDate.

[code]mDate = new GregorianCalendar(year, month, day).getTime();[/code]
That means set mDate to the time stamp generated by the given year, month, and day as interpreted by the Gregorian calendar as opposed to, say, the Atzec calendar.

That means set the calendar’s time based on the time stamp stored by mDate.

That means set mDate to the time stamp generated by the given year, month, and day as interpreted by the Gregorian calendar as opposed to, say, the Atzec calendar.


#3

Thank you. I wish the documentation had explained it as well. This helps a lot.