java使用Calendar 获取七天的时间

@Test
    public void Tes1(){

        String [] arr = new String[7];
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = null;
        for (int i=0;i<7;i++){
            c=Calendar.getInstance();
            c.add(Calendar.DAY_OF_MONTH, -i);
            arr[6-i] =sdf.format(c.getTime());
        }
        for (int i = 0; i < arr.length; i++) {
            System.err.println(arr[i]);
        }
    }
posted @ 2022-08-01 09:22  又一岁荣枯  阅读(1195)  评论(0编辑  收藏  举报