/**
* 獲取星期六和星期日工具類
*/
public class WeekdayUtil {
/**
* 獲取當前年所有星期六
* @param year 年份
* @return 日期集合
*/
public static List<String> getSaturdayInYear(int year){
List<String> dateList=new ArrayList<String>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = new GregorianCalendar(year, 0, 1);
int i = 1;
while (calendar.get(Calendar.YEAR) < year + 1) {
calendar.set(Calendar.WEEK_OF_YEAR, i++);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
if (calendar.get(Calendar.YEAR) == year) {
//dateList.add(dateFormat.format(calendar.getTime()));
}
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
if (calendar.get(Calendar.YEAR) == year) {
dateList.add(dateFormat.format(calendar.getTime()));
}
}
return dateList;
}
/**
* 獲取當前年所有星期日
* @param year 年份
* @return 日期集合
*/
public static List<String> getSundayInYear(int year){
List<String> dateList=new ArrayList<String>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = new GregorianCalendar(year, 0, 1);
int i = 1;
while (calendar.get(Calendar.YEAR) < year + 1) {
calendar.set(Calendar.WEEK_OF_YEAR, i++);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
if (calendar.get(Calendar.YEAR) == year) {
dateList.add(dateFormat.format(calendar.getTime()));
}
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
if (calendar.get(Calendar.YEAR) == year) {
//dateList.add(dateFormat.format(calendar.getTime()));
}
}
return dateList;
}
/**
* 獲取當前年所有星期六和星期日
* @param year 年份
* @return 日期集合
*/
public static List<String> getWeekendInYear(int year){
List<String> dateList=new ArrayList<String>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = new GregorianCalendar(year, 0, 1);
int i = 1;
while (calendar.get(Calendar.YEAR) < year + 1) {
calendar.set(Calendar.WEEK_OF_YEAR, i++);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
if (calendar.get(Calendar.YEAR) == year) {
dateList.add(dateFormat.format(calendar.getTime()));
}
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
if (calendar.get(Calendar.YEAR) == year) {
dateList.add(dateFormat.format(calendar.getTime()));
}
}
return dateList;
}
/**
* 獲取當前年某天到年底所有星期六
* @param year 當前年
* @param yyyy_MM_dd 某天
* @return 日期集合
*/
public static List<String> getSaturdayInYearAfterDay(int year,String yyyy_MM_dd){
List<String> dateList=new ArrayList<String>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = new GregorianCalendar(year, 0, 1);
int i = 1;
while (calendar.get(Calendar.YEAR) < year + 1) {
calendar.set(Calendar.WEEK_OF_YEAR, i++);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
if (calendar.get(Calendar.YEAR) == year && Integer.parseInt(dateFormat.format(calendar.getTime()).replaceAll("-","")) >= Integer.parseInt(yyyy_MM_dd.replaceAll("-",""))) {
//dateList.add(dateFormat.format(calendar.getTime()));
}
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
if (calendar.get(Calendar.YEAR) == year && Integer.parseInt(dateFormat.format(calendar.getTime()).replaceAll("-","")) >= Integer.parseInt(yyyy_MM_dd.replaceAll("-",""))) {
dateList.add(dateFormat.format(calendar.getTime()));
}
}
return dateList;
}
/**
* 獲取當前年某天到年底所有星期日
* @param year 當前年
* @param yyyy_MM_dd 某天
* @return 日期集合
*/
public static List<String> getSundayInYearAfterDay(int year,String yyyy_MM_dd){
List<String> dateList=new ArrayList<String>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = new GregorianCalendar(year, 0, 1);
int i = 1;
while (calendar.get(Calendar.YEAR) < year + 1) {
calendar.set(Calendar.WEEK_OF_YEAR, i++);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
if (calendar.get(Calendar.YEAR) == year && Integer.parseInt(dateFormat.format(calendar.getTime()).replaceAll("-","")) >= Integer.parseInt(yyyy_MM_dd.replaceAll("-",""))) {
dateList.add(dateFormat.format(calendar.getTime()));
}
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
if (calendar.get(Calendar.YEAR) == year && Integer.parseInt(dateFormat.format(calendar.getTime()).replaceAll("-","")) >= Integer.parseInt(yyyy_MM_dd.replaceAll("-",""))) {
//dateList.add(dateFormat.format(calendar.getTime()));
}
}
return dateList;
}
/**
* 獲取當前年某天到年底所有星期六和星期日
* @param year 當前年
* @param yyyy_MM_dd 某天
* @return 日期集合
*/
public static List<String> getWeekendInYearAfterDay(int year,String yyyy_MM_dd){
List<String> dateList=new ArrayList<String>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = new GregorianCalendar(year, 0, 1);
int i = 1;
while (calendar.get(Calendar.YEAR) < year + 1) {
calendar.set(Calendar.WEEK_OF_YEAR, i++);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
if (calendar.get(Calendar.YEAR) == year && Integer.parseInt(dateFormat.format(calendar.getTime()).replaceAll("-","")) >= Integer.parseInt(yyyy_MM_dd.replaceAll("-",""))) {
dateList.add(dateFormat.format(calendar.getTime()));
}
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
if (calendar.get(Calendar.YEAR) == year && Integer.parseInt(dateFormat.format(calendar.getTime()).replaceAll("-","")) >= Integer.parseInt(yyyy_MM_dd.replaceAll("-",""))) {
dateList.add(dateFormat.format(calendar.getTime()));
}
}
return dateList;
}
/**
* 獲取當月的所有星期六
* @param year 年份
* @param month 月份
* @return 日期集合
*/
public static List<String> getSaturdayInMonth(int year, int month) {
List<String> dateList=new ArrayList<String>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
List<String> list = new ArrayList<String>();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
int daySize = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int i = 0; i < daySize; i++) {
int week = calendar.get(Calendar.DAY_OF_WEEK);
if (week == Calendar.SATURDAY) {
dateList.add(dateFormat.format(calendar.getTime()));
}
calendar.add(Calendar.DATE, 1);
}
return dateList;
}
/**
* 獲取當月的所有星期日
* @param year 年份
* @param month 月份
* @return 日期集合
*/
public static List<String> getSundayInMonth(int year, int month) {
List<String> dateList=new ArrayList<String>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
List<String> list = new ArrayList<String>();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
int daySize = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int i = 0; i < daySize; i++) {
int week = calendar.get(Calendar.DAY_OF_WEEK);
if (week == Calendar.SUNDAY) {
dateList.add(dateFormat.format(calendar.getTime()));
}
calendar.add(Calendar.DATE, 1);
}
return dateList;
}
/**
* 獲取當月的所有星期六和星期日
* @param year 年份
* @param month 月份
* @return 日期集合
*/
public static List<String> getWeekendInMonth(int year, int month) {
List<String> dateList=new ArrayList<String>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
List<String> list = new ArrayList<String>();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
int daySize = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int i = 0; i < daySize; i++) {
int week = calendar.get(Calendar.DAY_OF_WEEK);
if (week == Calendar.SATURDAY ) {
dateList.add(dateFormat.format(calendar.getTime()));
}
if (week == Calendar.SUNDAY) {
dateList.add(dateFormat.format(calendar.getTime()));
}
calendar.add(Calendar.DATE, 1);
}
return dateList;
}
/**
* 獲取該月的某天到月底的所有星期六
* @param year 年份
* @param month 月份
* @param day 日期
* @return 日期集合
*/
public static List<String> getSaturdayInMonthAfterDay(int year, int month,int day) {
List<String> dateList=new ArrayList<String>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
List<String> list = new ArrayList<String>();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, day);
int daySize = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int i = 0; i < daySize-day+1; i++) {
int week = calendar.get(Calendar.DAY_OF_WEEK);
if (week == Calendar.SATURDAY ) {
dateList.add(dateFormat.format(calendar.getTime()));
}
calendar.add(Calendar.DATE, 1);
}
return dateList;
}
/**
* 獲取該月的某天到月底的所有星期日
* @param year 年份
* @param month 月份
* @param day 日期
* @return 日期集合
*/
public static List<String> getSundayInMonthAfterDay(int year, int month,int day) {
List<String> dateList=new ArrayList<String>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
List<String> list = new ArrayList<String>();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, day);
int daySize = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int i = 0; i < daySize-day+1; i++) {
int week = calendar.get(Calendar.DAY_OF_WEEK);
if (week == Calendar.SUNDAY) {
dateList.add(dateFormat.format(calendar.getTime()));
}
calendar.add(Calendar.DATE, 1);
}
return dateList;
}
/**
* 獲取該月的某天到月底的所有星期六和星期日
* @param year 年份
* @param month 月份
* @param day 日期
* @return 日期集合
*/
public static List<String> getWeekendInMonthAfterDay(int year, int month,int day) {
List<String> dateList=new ArrayList<String>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
List<String> list = new ArrayList<String>();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, day);
int daySize = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int i = 0; i < daySize-day+1; i++) {
int week = calendar.get(Calendar.DAY_OF_WEEK);
if (week == Calendar.SATURDAY ) {
dateList.add(dateFormat.format(calendar.getTime()));
}
if (week == Calendar.SUNDAY) {
dateList.add(dateFormat.format(calendar.getTime()));
}
calendar.add(Calendar.DATE, 1);
}
return dateList;
}
}
WeekdayUtil
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門迄汛,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人骤视,你說我怎么就攤上這事鞍爱。” “怎么了专酗?”我有些...
- 文/不壞的土叔 我叫張陵睹逃,是天一觀的道長。 經(jīng)常有香客問我,道長沉填,這世上最難降的妖魔是什么疗隶? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮翼闹,結(jié)果婚禮上斑鼻,老公的妹妹穿的比我還像新娘。我一直安慰自己猎荠,他們只是感情好坚弱,可當我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著关摇,像睡著了一般荒叶。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上输虱,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼命贴!你這毒婦竟也來了道宅?” 一聲冷哼從身側(cè)響起,我...
- 正文 年R本政府宣布嗜历,位于F島的核電站,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏梨州。R本人自食惡果不足惜痕囱,卻給世界環(huán)境...
- 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望暴匠。 院中可真熱鬧咐蝇,春花似錦、人聲如沸巷查。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽岛请。三九已至旭寿,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間崇败,已是汗流浹背盅称。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 《閉上眼睛才能看清楚自己》這本書是香海禪寺主持賢宗法師的人生體悟贡避,修行心得及講學錄痛黎,此書從六個章節(jié)講述了禪修是什么...
- 前言 Google Play應用市場對于應用的targetSdkVersion有了更為嚴格的要求。從 2018 年...