todayMonth = (TextView) findViewById(R.id.todayMonth); todayDay = (TextView) findViewById(R.id.todayDay); today = (TextView) findViewById(R.id.today); tommorowyMonth = (TextView) findViewById(R.id.tommorowyMonth); tommorow = (TextView) findViewById(R.id.tommorow); tomorrowTxt = (TextView) findViewById(R.id.tomorrowTxt); lastMonth = (TextView) findViewById(R.id.lastMonth); lastDay = (TextView) findViewById(R.id.lastDay); last = (TextView) findViewById(R.id.last); Date d = new Date(); getdate(d, 1);
public void getdate(Date d, int id) { DateFormatSymbols dfs = new DateFormatSymbols(); String[] months = dfs.getMonths(); SimpleDateFormat mdformat = new SimpleDateFormat("dd / MM / yyyy "); String strDate = mdformat.format(d); String dateStr[] = getdateVal(strDate); if (id == 1) { todayMonth.setText(months[d.getMonth()]); todayDay.setText(dateStr[0]); Calendar calendar = Calendar.getInstance(); int thisYear = calendar.get(Calendar.YEAR); int thisMonth = calendar.get(Calendar.MONTH); int thisDay = calendar.get(Calendar.DAY_OF_MONTH); Date dd = new Date(thisYear, thisMonth, thisDay + 1); date[0]=thisYear+"-"+thisMonth+"-"+thisDay; getdate(dd, 2); } else if (id == 2) { tommorowyMonth.setText(months[d.getMonth()]); tommorow.setText(dateStr[0]); tomorrowTxt = (TextView) findViewById(R.id.tomorrowTxt); tomorrowTxt.setText("TOMORROW"); Calendar calendar = Calendar.getInstance(); int thisYear = calendar.get(Calendar.YEAR); int thisMonth = calendar.get(Calendar.MONTH); int thisDay = calendar.get(Calendar.DAY_OF_MONTH); Date dd = new Date(thisYear, thisMonth, thisDay + 2); date[1]=thisYear+"-"+thisMonth+"-"+thisDay; getdate(dd, 3); } else if (id == 3) { lastMonth.setText(months[d.getMonth()]); lastDay.setText(dateStr[0]); Calendar calendar = Calendar.getInstance(); int thisYear = calendar.get(Calendar.YEAR); int thisMonth = calendar.get(Calendar.MONTH); int thisDay = calendar.get(Calendar.DAY_OF_MONTH); Date dd = new Date(thisYear, thisMonth, thisDay + 1); String dayOfTheWeek = (String) DateFormat.format("EEEE", dd); date[1]=thisYear+"-"+thisMonth+"-"+thisDay; last.setText(dayOfTheWeek); } } public String[] getdateVal(String date) { String str[] = date.split("/"); return str; }
No comments:
Post a Comment