Android Week Compare isSameWeek(Date date)

Here you can find the source of isSameWeek(Date date)

Description

is Same Week

License

Open Source License

Declaration

public static boolean isSameWeek(Date date) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static boolean isSameWeek(Date date) {
        Calendar beginningOfTheWeek = Calendar.getInstance();
        beginningOfTheWeek.set(Calendar.DAY_OF_WEEK,
                beginningOfTheWeek.getFirstDayOfWeek());
        beginningOfTheWeek.set(Calendar.HOUR, 0);
        beginningOfTheWeek.set(Calendar.MINUTE, 0);

        Calendar endOfTheWeek = Calendar.getInstance();
        endOfTheWeek.set(Calendar.DAY_OF_WEEK,
                endOfTheWeek.getFirstDayOfWeek());
        endOfTheWeek.add(Calendar.DAY_OF_WEEK, 7);
        endOfTheWeek.set(Calendar.HOUR, 23);
        endOfTheWeek.set(Calendar.MINUTE, 59);

        return date.after(beginningOfTheWeek.getTime())
                && date.before(endOfTheWeek.getTime());
    }//w w w  .j a v a 2s.c  o  m
}

Related

  1. isSameWeek(Time t1, Time t2)
  2. isWithinTheWeek(Date sunday, Date now)