tags:

views:

249

answers:

1

How may I get week start timestamp (2010-03-01 00:00:00 UTC) and week end timestamp (2010-03-08 00:00:00 UTC) given a java.util.Date (or Joda DateTime), or year and ISO week number, using Java SE API and Joda Time?

A: 

JodaTime has support for ISO week numbers (see here). For example:

java.util.Date date = new java.util.Date();
DateTime dateTime = new DateTime(date);
int isoWeek = dateTime.getWeekOfWeekyear();

You can also set the "start of aweek" using something like this:

DateTime startOfWeek = dateTime.withWeekOfWeekyear(4).withDayOfWeek(1).withTime(0, 0, 0, 0);
skaffman