Android Day Get getDateOfLastSunday(Date d)

Here you can find the source of getDateOfLastSunday(Date d)

Description

get Date Of Last Sunday

Declaration

public static Date getDateOfLastSunday(Date d) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static Date getDateOfLastSunday(Date d) {
        Calendar c = Calendar.getInstance();
        c.setTime(d);//w w w .  ja va2s .  c o m

        int weekday = c.get(Calendar.DAY_OF_WEEK);

        if (weekday != Calendar.SUNDAY) {
            int days = (Calendar.SUNDAY - weekday) % 7;
            c.add(Calendar.DAY_OF_YEAR, days);
        }

        c.set(Calendar.HOUR, 0);
        c.set(Calendar.AM_PM, Calendar.AM);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);

        Date date = c.getTime();

        return date;
    }
}

Related

  1. getCurrentDay()
  2. getSmartDateString(long time, String extString, String zeroDayString)
  3. getWeatherDateStr(int day)
  4. getArrayDiffDays(String startDate, String endDate)
  5. getIndexDay(Date origin, int index)
  6. getStartNextDay(Date d2)
  7. getNextDay(Date d2)
  8. getNextDateForDay(int calendarDay)
  9. getHashByDay(String date)