请教 得到当前日期的本月每周星期四的日期,万分感谢!!
例如:当前日期2010-8-27
   得到:2010-8-5  是:星期四
         2010-8-12 是:星期四
         2010-8-19 是:星期四
         2010-8-26 是:星期四
感谢!!!!!!!!!

解决方案 »

  1.   


    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
    String str = "2010-08-27";
    Date date1 = sf.parse(str);
    Calendar cal1 = Calendar.getInstance();
    int endDay = cal1.getActualMaximum(Calendar.DAY_OF_MONTH);
    cal1.set(cal1.get(cal1.YEAR), cal1.get(cal1.MONTH), cal1
    .getActualMinimum(Calendar.DAY_OF_MONTH));
    for (int startDay = 1; startDay <= endDay; startDay++) {
    if (5 == cal1.get(Calendar.DAY_OF_WEEK)) {
    // System.out.println("ddd");
    System.out.println(sf.format(cal1.getTime()));
    }
    cal1.add(cal1.DAY_OF_MONTH, 1);
    }
      

  2.   

    少写了一句
    Calendar cal1 = Calendar.getInstance();
    cal1.setTime(date1);
    int endDay = cal1.getActualMaximum(Calendar.DAY_OF_MONTH);
      

  3.   

    不好意思,放错地方了,谢谢你
    我想问如何用sql语句写
      

  4.   

    SQL语句得到系统当前的星期:Select DateName(WeekDay,GetDate())
    获取指定年月的星期:Select DateName(WeekDay,'2010-8-12')
      

  5.   

    SET DATEFIRST 1
     SELECT  convert(varchar(8), getdate(),120)+ltrim(number) 
    from master..spt_values
    where number between 1 and 31
    and type='p'
    and DATEPART(WEEKDAY,convert(varchar(8), getdate(),120)+ltrim(number))=4--------------------
    2010-08-5
    2010-08-12
    2010-08-19
    2010-08-26(4 行受影响)
      

  6.   

    ---5楼的有点问题
    SET DATEFIRST 1
     SELECT  [date]=dateadd(day,number,convert(varchar(8),getdate(),120)+'01') 
    from master..spt_values
    where number between 1 and 31
    and type='p'
    and month(dateadd(day,number,convert(varchar(8),getdate(),120)+'01'))=month(getdate()) 
    and DATEPART(WEEKDAY,dateadd(day,number,convert(varchar(8),getdate(),120)+'01'))=4
    date
    -----------------------
    2010-08-05 00:00:00.000
    2010-08-12 00:00:00.000
    2010-08-19 00:00:00.000
    2010-08-26 00:00:00.000(4 行受影响)