get Sunday Date - Java java.util

Java examples for java.util:Day

Description

get Sunday Date

Demo Code


//package com.java2s;

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

public class Main {

    public static Date getSundayDate(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);/*from w w w.  j a  v  a 2 s.  c  o  m*/
        int day = calendar.get(Calendar.DAY_OF_WEEK);
        day = (day + 6) % 7;
        day = day == 0 ? 7 : day;
        calendar.add(Calendar.DAY_OF_YEAR, 7 - day);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }
}

Related Tutorials