Android TextView Set initDate(TextView view,int days)

Here you can find the source of initDate(TextView view,int days)

Description

init Date

Declaration

public static void initDate(TextView view,int days) 

Method Source Code

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.widget.TextView;

public class Main{
    public static void initDate(TextView view,int days) {
      //from  w w w  . j a  v  a 2 s .c om
      Calendar c = Calendar.getInstance();
      c.add(Calendar.DAY_OF_MONTH, days);
      int mYear = c.get(Calendar.YEAR);
      int mMonth = c.get(Calendar.MONTH);
      int mDay = c.get(Calendar.DAY_OF_MONTH);
      String dateStr = new StringBuilder().append(mYear).append("-").append(
            format(mMonth + 1)).append("-").append(format(mDay)).toString();
      view.setText(dateStr+" "+getWeek(dateStr));
   }
    private static String format(int x) {
      String s = "" + x;
      if (s.length() == 1)
         s = "0" + s;
      return s;
   }
    public static String getWeek(String date) {
      Date dat = null;
      SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
      try {
         dat = simpleDateFormat.parse(date);
      } catch (ParseException e) {
         e.printStackTrace();
      }
      return getChineseWeek(dat);
   }
}

Related

  1. setText(TextView tv, String str)
  2. setText(TextView tv, int str)
  3. setHtml(TextView view, String html)
  4. setHtml(Activity activity, View parent, int elementId, int resId)
  5. setBold(TextView tv)
  6. manageVisibiltyFieldSpeech(Context context, ImageButton button, AutoCompleteTextView text, int idRightof, int idLeftOf, int idBelow)
  7. setupMarquee(TextView textView, String text)