根据指定日期段找出符合条件的日期,例如指定日期段里是星期一,星期二,星期三的是是哪些天
2009-04-13 17:18
369 查看
public static List<String> getMatchDateStrs(String[] weekdays, String start, String end)
throws Exception
{
List<String> list = new ArrayList<String>();
String[] weeks = {"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
String datestr = null;
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat weekdayformat = new SimpleDateFormat("E");
Calendar calendar = Calendar.getInstance();
calendar.setTime(dateformat.parse(start));
calendar.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));
datestr = dateformat.format(calendar.getTime());
while (datestr.compareToIgnoreCase(end)<1)
{
for (int i = 0; i < weekdays.length; i++)
{
if (!"".equals(weekdays[i]))
{
int temp = Integer.parseInt(weekdays[i]);
if (weeks[temp-1].equals(weekdayformat.format(calendar.getTime())))
{
list.add(datestr);
}
}
}
calendar.add(Calendar.DAY_OF_MONTH, 1);
datestr = dateformat.format(calendar.getTime());
}
return list;
}
throws Exception
{
List<String> list = new ArrayList<String>();
String[] weeks = {"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
String datestr = null;
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat weekdayformat = new SimpleDateFormat("E");
Calendar calendar = Calendar.getInstance();
calendar.setTime(dateformat.parse(start));
calendar.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));
datestr = dateformat.format(calendar.getTime());
while (datestr.compareToIgnoreCase(end)<1)
{
for (int i = 0; i < weekdays.length; i++)
{
if (!"".equals(weekdays[i]))
{
int temp = Integer.parseInt(weekdays[i]);
if (weeks[temp-1].equals(weekdayformat.format(calendar.getTime())))
{
list.add(datestr);
}
}
}
calendar.add(Calendar.DAY_OF_MONTH, 1);
datestr = dateformat.format(calendar.getTime());
}
return list;
}
相关文章推荐
- 找出符合以下条件的Troitsky数,将该数的首位数字移动到末位数字之后得到的数是原数的整数倍 例如:将142857的首位数字1移动到末位之后得到的数是428571,而428571=3*1
- sql 多条件组合查询,并根据指定类别找出所有最小子类别的SQL语句备忘
- 找出所有符合条件的记录的指定字段并分组统计个数,返回指定格式。
- 找出所有符合条件的记录的指定字段并分组统计个数,返回指定格式。
- 根据起止日期构建指定查询条件:第N周(yyyy-MM-dd/yyyy-MM-dd)
- sql 多条件组合查询,并根据指定类别找出所有最小子类别的SQL语句备忘
- 根据条件筛选指定的日期
- 多条件组合查询,并根据指定类别找出所有最小子类别的SQL语句备忘
- 根据日期范围查询符合条件的数据
- ASPxGridview根据条件将符合条件的行颜色改变等
- 根据条件获取json(无限级)中指定的对象
- 对数据库根据符合条件的记录 逐个进行更新使用的连接语句
- 两表更新:根据条件从一个表里面查询出符合条件的结果更新另一个表
- 根据当前日期推算星期一和星期天使几号。推算出一个完整的周
- 根据条件判断查询指定条件还是所有条件
- 根据顺序对个数找符合条件的数列
- 根据当前时间取得星期一跟星期天的日期
- C#获取指定年份第一个星期一具体日期的方法
- 根据当前日期(指定日期),获取下周日期
- js日期操作之根据指定格式获取日期