Leap year date time Java Android example

GregorianCalendar cal = new GregorianCalendar(); Boolean b = cal.isLeapYear(2012); // true, Android example.

public class MainActivity extends Activity {
TextView txtV;
	Context cntx;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        txtV = (TextView)findViewById(R.id.idLabel);
        cntx = this;
        StringBuilder strBuild = new StringBuilder();
 
         GregorianCalendar cal = new GregorianCalendar();
         Boolean b = cal.isLeapYear(2012); // true
         strBuild.append("Is leap year 2012? " + b + "\n");
         b = cal.isLeapYear(2014);         // false
         strBuild.append("Is leap year 2014? " + b + "\n");
 
 
         txtV.setText(strBuild);
    }
}
This entry was posted in Android Examples Code and tagged , , , , . Bookmark the permalink.


Comments are closed.

4,660 views