get First Day Of Current Week - Android java.util

Android examples for java.util:Week

Description

get First Day Of Current Week

Demo Code


import android.util.Log;
import java.text.DateFormatSymbols;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Locale;

public class Main{
    private static final String LOG_TAG = CalendarUtil.class
            .getSimpleName();//from  w w w  . j a va  2 s.  co m
    public static Calendar getFirstDayOfCurrentWeek() {
        Log.d(LOG_TAG, "getFirstDayOfCurrentWeek() is called.");
        Calendar c = Calendar.getInstance();
        return getDayOfWeek(c, Calendar.MONDAY,
                c.get(Calendar.WEEK_OF_YEAR), c.get(Calendar.YEAR));
    }
    public static Calendar getDayOfWeek(final int dayOfWeek,
            final int weekOfYear, final int year) {
        Log.d(LOG_TAG,
                "getDayOfWeek(final int dayOfWeek, final int weekOfYear, final int year) is called.");
        return getDayOfWeek(Calendar.getInstance(), dayOfWeek, weekOfYear,
                year);
    }
    private static Calendar getDayOfWeek(final Calendar c,
            final int dayOfWeek, final int weekOfYear, final int year) {
        c.clear();

        c.set(Calendar.YEAR, year);
        c.set(Calendar.WEEK_OF_YEAR, weekOfYear);
        c.set(Calendar.DAY_OF_WEEK, dayOfWeek);

        return c;
    }
}

Related Tutorials