Set week date for Calendar in Java

Description

The following code shows how to set week date for Calendar.

Example


/*from   w w  w.  j  a  v  a2 s  .co  m*/
import java.text.DateFormat;
import java.util.Calendar;
import java.util.SimpleTimeZone;

public class Main {
  public static void main(String[] args) {
    Calendar calendar = Calendar.getInstance();
    if (calendar.isWeekDateSupported()) {
      System.out.println("Number of weeks in this year: "
          + calendar.getWeeksInWeekYear());
      System.out.println("Current week number: "
          + calendar.get(Calendar.WEEK_OF_YEAR));
    }

    calendar.setWeekDate(2012, 16, 3);
    System.out.println(DateFormat.getDateTimeInstance(DateFormat.LONG,
        DateFormat.LONG).format(calendar.getTime()));

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Date »




Date Get
Date Set
Date Format
Date Compare
Date Convert
Date Calculation
Date Parse
Timezone