This is simple but useful stuff in Android. Find the current day, week,month and year.
You have just do in oncreate in Actvity
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_WEEK);
int week=calendar.get(Calendar.WEEK_OF_MONTH);
int week_of_year=calendar.get(Calendar.WEEK_OF_YEAR);
int month=calendar.get(Calendar.MONTH);
int year=calendar.get(Calendar.YEAR);
Log.d("TAG", "Today is ->"+day);
Log.d("TAG", "Week of Month is ->"+week);
Log.d("TAG", "Week of year is ->"+week_of_year);
Log.d("TAG", "Month is ->"+month);
Log.d("TAG", "Year is ->"+year);
}
}
Output of Following Code:
Application Running Date: 2023- July- 9- Tuesday
07-09 19:29:46.271: D/TAG(1110): Today is ->3
07-09 19:29:46.271: D/TAG(1110): Week of Month is ->2
07-09 19:29:46.301: D/TAG(1110): Week of year is ->28
07-09 19:29:46.301: D/TAG(1110): Month is ->6
07-09 19:29:46.301: D/TAG(1110): Year is ->2013
Happy coding.




0 comments
Posts a comment