get Monday Of This Week as String - Android java.util

Android examples for java.util:Week

Description

get Monday Of This Week as String

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 getMondayOfThisWeek(int i) {
        Calendar c = Calendar.getInstance();
        int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1;
        if (dayofweek == 0)
            dayofweek = 7;// w  w  w.  j  a  v a 2s  . com
        c.add(Calendar.DATE, -dayofweek + 1);
        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