get Week Start Date - Java java.util

Java examples for java.util:Week

Description

get Week Start Date

Demo Code


//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static Date getWeekStartDate(Date date) {
        if (date == null) {
            date = new Date();
        }/* w w  w  .  j  a va  2s . c  o m*/
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int week = cal.get(Calendar.DAY_OF_WEEK);
        if (week == 1) {
            cal.add(Calendar.DATE, -6);
        } else {
            cal.add(Calendar.DATE, (-week + 2));
        }
        return cal.getTime();
    }
}

Related Tutorials