Skip to content

Instantly share code, notes, and snippets.

@jezinka
Created March 6, 2017 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jezinka/e5e97e78244c96fed2dc0ae9b7134b67 to your computer and use it in GitHub Desktop.
Save jezinka/e5e97e78244c96fed2dc0ae9b7134b67 to your computer and use it in GitHub Desktop.
private Date getSaturdayDate(Date date) {
if(date == null){
date = new Date();
}
Calendar calendarInstance = Calendar.getInstance();
calendarInstance.setTime(date);
int dayOfWeek = calendarInstance.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == Calendar.SATURDAY) {
return date;
}
calendarInstance.add(Calendar.DAY_OF_WEEK, -dayOfWeek);
return calendarInstance.getTime();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment