如题,我传入一个如“2007-10-01”的日期,怎么计算出这个日期所在的旬?请各位高人指点。

解决方案 »

  1.   


    使用 DAY_OF_MONTH,计算出该日期是该月份的第几天
    if(DAY_OF_MONTH <= 10) 
        上旬;
        else if(10 < DAY_OF_MONTH <= 20)
             中旬;
        else
             下旬;
      

  2.   


    public class Test { public static int getDay(String dateIn) {
    String day = dateIn.substring(dateIn.length() - 2, dateIn.length());
    return Integer.parseInt(day);
    } public static void main(String[] args) {
    String d = "2007-09-12";
    int day = getDay(d);
    System.out.println(day+"日");
    if (day > 0 && day <= 10) {
    System.out.println("上旬");
    } else if (day > 10 && day <= 20) {
    System.out.println("中旬");
    } else if (day > 20 && day <= 31) {
    System.out.println("下旬");
    } else {
    System.out.println("输入的日期错误!");
    }
    }
    }