get Week End Date - Java java.util

Java examples for java.util:Week

Description

get Week End Date

Demo Code


//package com.java2s;

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

public class Main {

    public static Date getWeekEndDate(Date date) {
        if (date == null) {
            date = new Date();
        }//from www  .j  ava 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, (7 - week + 1));
        }
        return cal.getTime();
    }
}

Related Tutorials