如何获得周数。 (我有约会)?

How to get week number. (I have date)?

我目前正在做一个项目,需要找到给定日期的周数。

你能给我一个代码片段来解决我的问题吗?

谢谢。

这应该可以解决您的问题:

Calendar cal = Calendar.getInstance();
cal.setTime(date);
int weekOfYear = ca.get(Calendar.WEEK_OF_YEAR);

你可以试试这个

Calendar now = Calendar.getInstance();


  now.set(Calendar.YEAR,2013);
  now.set(Calendar.MONTH,04);//0- january ..4-May
  now.set(Calendar.DATE, 04);

System.out.println("Current week of month is : " +
            now.get(Calendar.WEEK_OF_MONTH));

System.out.println("Current week of year is : " +
            now.get(Calendar.WEEK_OF_YEAR));