get Day OF Week - Android java.util

Android examples for java.util:Week

Description

get Day OF Week

Demo Code

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {

  public static String getDayOFWeek(int dayindex, int witchWeek) {
    SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
    int dayPlus = getDayPlus(dayindex);

    GregorianCalendar currentDate = new GregorianCalendar();
    currentDate.add(GregorianCalendar.DATE, dayPlus + witchWeek * 7);

    Date monday = currentDate.getTime();

    String preMonday = df1.format(monday);
    return preMonday;
  }/*from   w  w w .  j  a v  a2 s.c om*/
  public static int getDayPlus(int dayindex) {
    Calendar cd = Calendar.getInstance();
    int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK) - 1; 

    return dayindex - dayOfWeek;
}
}

Related Tutorials