• java 日期递增


      

     1     public static void main(String[] args) throws ParseException {
     2         // 方法一
     3 //        Format f = new SimpleDateFormat("yyyy-MM-dd");
     4 //
     5 //        Date today = new Date();
     6 //        System.out.println("今天是:" + f.format(today));
     7 //
     8 //        Calendar c = Calendar.getInstance();
     9 //        c.setTime(today);
    10 //        c.add(Calendar.DAY_OF_MONTH, 1);// 今天+1天
    11 //
    12 //        Date tomorrow = c.getTime();
    13 //        System.out.println("明天是:" + f.format(tomorrow));
    14 
    15         // 方法二
    16         List<NutMap> maps = new ArrayList<NutMap>();
    17         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    18         Calendar cal = Calendar.getInstance();
    19         cal.setTime(new Date());
    20         int sum = 3;
    21         int i = 0;
    22         for (int j = 0; j < sum ; j++) {
    23             cal.add(cal.DATE, 1);
    24             if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
    25                 sum++;
    26             } else {
    27                 NutMap map = new NutMap();
    28                 map.addv("data" + i, format.format(cal.getTime()));
    29                 i++;
    30                 maps.add(map);
    31             }
    32         }
    33         System.out.println(maps);
    34     }
  • 相关阅读:
    P2813 母舰
    P5367 【模板】康托展开
    P1816 忠诚
    P3865 【模板】ST表
    P1913 L国的战斗之伞兵
    P4939 Agent2
    P1894 [USACO4.2]完美的牛栏The Perfect Stall
    P5017 摆渡车
    P1330 封锁阳光大学
    P5018 对称二叉树
  • 原文地址:https://www.cnblogs.com/xjbBill/p/7066479.html
Copyright © 2020-2023  润新知