Skip to content

Instantly share code, notes, and snippets.

@pcdinh
Created November 17, 2009 09:44
Show Gist options
  • Save pcdinh/236790 to your computer and use it in GitHub Desktop.
Save pcdinh/236790 to your computer and use it in GitHub Desktop.
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
java.util.Date date = new java.util.Date();
String today = dateFormat.format(date);
Calendar calendar = Calendar.getInstance();
// set the calendar time (here, we set it to "today" / "now" date)
calendar.setTime(date);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); // first day of week.
String firstDayInWeek = dateFormat.format(calendar.getTime());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment