我不知道有没有新的API,就想到一个土方法:取那个月的一号,得到它是周几,然后自己算了第几周的星期几是几号

解决方案 »

  1.   

    用Calendar类,too easy!
    不明白的地方看javadoc
      

  2.   

    大意是这样的,自己多试几次便可以得到准确的日期了,注意:1,2...代表的week, month是不同的!例如,1不是星期一:)
    import java.util.*;public class datetest {
      public datetest() {
      }
      public static void main(String[] args) {
        datetest datetest1 = new datetest();
        Calendar c = Calendar.getInstance();
        String s = datetest1.getTime(1,2);
        System.out.println("s:" + s);
      }
      public String getTime(int week,int day){
          Calendar c = Calendar.getInstance();
          c.set(Calendar.WEEK_OF_MONTH,week);
          c.set(Calendar.DAY_OF_WEEK,day);
          return c.getTime().toString();
      }
    }
      

  3.   

    终于调出来了
    呵呵:)
    //年月周求日期
    SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM F E");
    java.util.Date date2= formatter2.parse("2003-05 5 星期五"); 
    SimpleDateFormat formatter3 = new SimpleDateFormat("yyyy-MM-dd");
    String mydate2=formatter3.format(date2);
    out.println(mydate2);
    out.println("<br>");("yyyy-MM F E");
    前边为年 月 F为第几周  E为周几
    比如几天就是("2003-05 5 星期五"); 
    2003年5月的第五个周五
      

  4.   

    我也知道用Calendar,但我没想出究竟如何用它,比如WEEK_OF_MONTH, DAY_OF_WEEK这些field来算出结果,才来这求救,大家能具体一点吗?
      

  5.   

    leshui(大象无形)(有物混成,先天地生)  不是已经给出来了吗?SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM F E");
    java.util.Date date2= formatter2.parse("2003-05 5 星期五"); 这样好用
      

  6.   

    Calendar cal = Calendar.getInstance();
    cal.set(year,month,1);
    这个月第2周
    cal.add(cal.WEEK_OF_MONTH,1);这个周第2天
    cal.add(Calendar.DAY_OF_WEEK,1);
      

  7.   

    class Test{static int getDate(int year, int month, int week, int day)
    {
    for(int date=1;date<=31;date++)
    {
    GregorianCalendar gc = new GregorianCalendar(year, month -1, date);
    if(gc.get(Calendar.WEEK_OF_MONTH) == week && gc.get(Calendar.DAY_OF_WEEK) == day)
    {
    return date;
    }
    }
    return 0;
    }
    static public void main(String[] args)
    { System.out.println(getDate(2003,5,5,6)); //2003 年5月第五周第五天}
    }终于成功了,注意每周周日为第一天。
      

  8.   

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-F");
    Date date = df.parse("2003-05-2");

    这个"F"得到的是一个月的第几个星期日,上面例子返回5月11号,五月份的第二个星期天。