java 数字左补齐0

 NumberFormat nf = NumberFormat.getInstance();
        //设置是否使用分组
        nf.setGroupingUsed(false);
        //设置最大整数位数
        nf.setMaximumIntegerDigits(2);
        nf.setMinimumIntegerDigits(2);

//可以左补齐两位数的数字

//以下是查询当前天数的所有日期
     String nowDay=getNowYMD();
     String curDayStr=nowDay.substring((nowDay.length()-2), nowDay.length());
     List list = new ArrayList();
     Calendar aCalendar = Calendar.getInstance(Locale.CHINA);
     int year = aCalendar.get(Calendar.YEAR);//年份
     int month = aCalendar.get(Calendar.MONTH) + 1;//月份
//     int day = aCalendar.getActualMaximum(Calendar.DATE);
     int day=Integer.valueOf(curDayStr);
     for (int i = day; i >0; i--) {
         String aDate = String.valueOf(year)+"-"+nf.format(month)+"-"+nf.format(i);
 
         list.add(aDate);
     }
     return list;

posted @ 2019-01-08 13:37  HalleyZ  阅读(1400)  评论(0编辑  收藏  举报