本文介紹了java獲取給定日期的一年中的一周的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時(shí)送ChatGPT賬號(hào)..
給定日期,我如何獲得一年中的一周?我嘗試了以下代碼:
how can I get a week of the year given a date? I tried the following code:
Calendar sDateCalendar = new GregorianCalendar();
sDateCalendar.set(Integer.parseInt(sDateYearAAAA), Integer.parseInt(sDateMonthMM)-1, Integer.parseInt(sDateDayDD));
System.out.format("sDateCalendar %tc
", sDateCalendar);
iStartWeek = sDateCalendar.getWeekYear();
System.out.println("iStartWeek "+iStartWeek+ " "+sDateCalendar.WEEK_OF_YEAR);
我得到:sDateCalendar lun 4 月 23 日 11:58:39 CEST 2012iStartWeek 2012 3
and i obtain: sDateCalendar lun apr 23 11:58:39 CEST 2012 iStartWeek 2012 3
一年中正確的星期是 17.有人可以幫我嗎?
while the correct week of year is 17. Can someone help me ?
推薦答案
你使用的是sDateCalendar.WEEK_OF_YEAR,即靜態(tài)整數(shù)WEEK_OF_YEAR,見java.util.Calendar類的源碼:
You are using sDateCalendar.WEEK_OF_YEAR, which is the static integer WEEK_OF_YEAR, see the source of the java.util.Calendar class:
public final static int WEEK_OF_YEAR = 3;
要獲取周數(shù),您應(yīng)該使用:
To get the week number, you should be using:
sDateCalendar.get(Calendar.WEEK_OF_YEAR);
這篇關(guān)于java獲取給定日期的一年中的一周的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!