Code example for Calendar

Methods: add, clone, compareTo, get, getTime, set

0
        (new View.OnClickListener() 
        {	 
        	@Override 
			public void onClick(View v) 
        	{ 
                calendar.set(startDateField.getYear(), startDateField.getMonth(), startDateField.getDayOfMonth());
                startDate = calendar.getTime();
                startyear = String.format("%04d", calendar.get(Calendar.YEAR));
                startmonth = String.format("%02d", calendar.get(Calendar.MONTH)+1);
                startday = String.format("%02d", calendar.get(Calendar.DAY_OF_MONTH));
                Calendar cal2 = (Calendar) calendar.clone();
                calendar.set(endDateField.getYear(), endDateField.getMonth(), endDateField.getDayOfMonth());
                endDate = calendar.getTime();
                endyear = String.format("%04d", calendar.get(Calendar.YEAR));
                endmonth = String.format("%02d", calendar.get(Calendar.MONTH)+1);
                endday = String.format("%02d", calendar.get(Calendar.DAY_OF_MONTH));
                if (cal2.compareTo(calendar) == 1) {
                	Toast toast = Toast.makeText(DateScreen.this,
                			"End Date must be after start date.",  
                			Toast.LENGTH_LONG);
                	toast.show();
                	return; 
                } 
                cal2.add(Calendar.YEAR, 1);
                if (cal2.compareTo(calendar) == -1) {
                	Toast toast = Toast.makeText(DateScreen.this,
                			"Maximum historical data that can be pulled at one time is one year.",  
                			Toast.LENGTH_LONG);
                	toast.show();
                	return;