獲取每年的第幾周集合

2021-10-10 09:05:28 字數 1634 閱讀 2149

public class dateutil else if(time.length()==110)

date date = new date();

******dateformat sdf = new ******dateformat("yyyy-mm-dd hh:mm:ss");

try catch (exception e)

string last12months = new string[12];

calendar cal = calendar.getinstance();

//設定輸入條件時間

cal.settime(date);

cal.set(calendar.month, cal.get(calendar.month)+1); //要先+1,才能把本月的算進去

for(int i=0; i<12; i++)

return last12months;

}public static string getlast6months(string time)else if(time.length()==110)

date date = new date();

******dateformat sdf = new ******dateformat("yyyy-mm-dd hh:mm:ss");

try catch (exception e)

string last6months = new string[6];

calendar cal = calendar.getinstance();

//設定輸入條件時間

cal.settime(date);

cal.set(calendar.month, cal.get(calendar.month)+1); //要先+1,才能把本月的算進去

for(int i=0; i<6; i++)

return last6months;

}public static string addzerofornum(string str, int strlength)

}return str;

}public string getweek(string datetime)catch (parseexception e)

return week;

}/**

* 獲取過去7天內的日期陣列

* @param intervals intervals天內

* @return 日期陣列

*/public static arraylistgetdays(int intervals)

return pastdayslist;

}/**

* 獲取過去第幾天的日期

* @param past

* @return

*/public static string getpastdate(int past)

public static string getweekandyear()

strings[strings.length-i-1]=year+"-"+week+"周";

}return strings;

}public static void main(string args)

}

JAVA獲取日期屬於當年第幾周

string today 2017 11 11 dateformat format new dateformat yyyy mm dd date date format.parse today calendar calendar calendar.getinstance calendar.setfi...

獲取當天是當年 當月的第幾周

引用命名空間 using system.globalization 示例 datetime date datetime.now 獲取指定時間是當年的第幾周 gregoriancalendar gc new gregoriancalendar int weekofyear gc.getweekofye...

獲取當天是當年 當月的第幾周

引用命名空間 using system.globalization 示例 datetime date datetime.now 獲取指定時間是當年的第幾周 gregoriancalendar gc new gregoriancalendar int weekofyear gc.getweekofye...