获取自定义格式的时间
最后更新于:2022-04-01 20:24:43
~~~
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import cn.com.agree.ab.trade.core.Trade;
/**
* getMonthWeekends(Trade trade,int month,int year) throws IOException{
List hostDays = new ArrayList();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month-1);
cal.set(Calendar.DAY_OF_MONTH, 1);
int startIndex = cal.get(Calendar.DAY_OF_WEEK) -1 ; // 0~6 表示 周日 ~ 周六
int endIndex = startIndex + getLastDayOfMonth(year, month) - 1;
int startday = 1;
for (int i = 0; i < 42; i++) {
if (i >= startIndex && i <= endIndex) {
cal.set(Calendar.DAY_OF_MONTH, startday);
if(cal.get(Calendar.DAY_OF_WEEK)==1||cal.get(Calendar.DAY_OF_WEEK)==7){
hostDays.add(startday+"");
}
startday++;
}
}
return hostDays;
}
public static boolean isLeapYear(int year) {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
public static int getLastDayOfMonth(int year, int month) {
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8
|| month == 10 || month == 12) {
return 31;
}
if (month == 4 || month == 6 || month == 9 || month == 11) {
return 30;
}
if (month == 2) {
if (isLeapYear(year)) {
return 29;
} else {
return 28;
}
}
return 0;
}
}
~~~
';
-
*
- 功能说明 * 字符串处理工具 *
* 例如:
* 使用例子说明 String a=NetCheck.getdataString("yyyyMMdd");
*