我目前正在开发一个需要查找给定日期的周数的项目。
你可以给我一个代码片段来解决我的问题吗?
感谢。
答案 0 :(得分:6)
你可以试试这个
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));
答案 1 :(得分:0)
这可以解决您使用此问题:
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int weekOfYear = ca.get(Calendar.WEEK_OF_YEAR);