首页 > 代码库 > 计算当前日期是一年中的第几周

计算当前日期是一年中的第几周

    public static void main(String[] args) {        Calendar gc = Calendar.getInstance();        int week=gc.get(Calendar.WEEK_OF_YEAR);//返回一年中的第几周        System.out.print(week);    }

计算包含日期的周

    public static void main(String[] args) {        SimpleDateFormat format = new java.text.SimpleDateFormat("yyyyMMdd");        Calendar gc = Calendar.getInstance();        String t = format.format(gc.getTime());        String t1 = String.valueOf(gc.get(Calendar.WEEK_OF_YEAR));        String val = t +" 第"+ t1+"周";        System.out.println(val);        String sub= val.substring(0, 4)+val.substring(10, 12);        System.out.println(sub);    }