Date Calendar Java Android Example

Calendar cal = new GregorianCalendar(), int year = cal.get(Calendar.YEAR),
ERA, MONTH, DAY_OF_MONTH, DAY_OF_WEEK, Android example code.

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;
        Calendar cal = new GregorianCalendar();
 
     int era = cal.get(Calendar.ERA);  // 0 B.C. before Christ, 1 Anno Domini              
     txtV.setText(txtV.getText() +"\n" +  era);
     int year = cal.get(Calendar.YEAR);   // 2011          
     txtV.setText(txtV.getText() +"\n" +  year);
     int month = cal.get(Calendar.MONTH);    // 0 is Januar       
     txtV.setText(txtV.getText() +"\n" +  month);
     int day = cal.get(Calendar.DAY_OF_MONTH); // 1 to 31     
     txtV.setText(txtV.getText() +"\n" +  day);
     int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // 1=Sunday, 2=Monday ...
     txtV.setText(txtV.getText() +"\n" +  dayOfWeek);
 
    }
}
This entry was posted in Android Examples Code and tagged , , , . Bookmark the permalink.


Comments are closed.



5,439 views