This example shows how to get / Display the current month, date and year from calendar. To acomplish this I have used Calender.getInstance() method of Calender class. let's see the code example:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Calendar c = Calendar.getInstance();
String[]monthName={"January","February","March", "April", "May", "June", "July",
"August", "September", "October", "November",
"December"};
String month=monthName[c.get(Calendar.MONTH)];
System.out.println("Month name:"+month);
int year=c.get(Calendar.YEAR);
int date=c.get(Calendar.DATE);
textView=(TextView)findViewById(R.id.date);
textView.setText(" "+ date+ " "+month+ " /" + "" + year);
}
0 Comment(s)