[英]How to get week number. (I have date)?
我目前正在從事一個需要查找給定日期的星期數的項目。
您能為我的問題提供一個代碼段嗎?
謝謝。
你可以試試這個
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));
這樣可以解決您的問題:
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int weekOfYear = ca.get(Calendar.WEEK_OF_YEAR);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.