get Sunday Of This Week - Android java.util

Android examples for java.util:Week

Description

get Sunday Of This Week

Demo Code


//package com.java2s;

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

public class Main {
    public static String fm = "yyyy/MM/dd/";
    public static String fm2 = "MM/dd/";

    public static String getSundayOfThisWeek(int i) {
        Calendar c = Calendar.getInstance();
        int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1;
        if (dayofweek == 0)
            dayofweek = 7;/*from  w w  w .j  av a  2s .c o  m*/
        c.add(Calendar.DATE, -dayofweek + 7);
        SimpleDateFormat sdf = null;
        if (i == 1) {
            sdf = new SimpleDateFormat(fm);
        } else if (i == 2) {
            sdf = new SimpleDateFormat(fm2);
        }
        return sdf.format(c.getTime());
    }
}

Related Tutorials