日期的一些应用

1.SimpleDateFormat simDate= new SimpleDateFormat("yyyyMM");

      Date date = simDate.parse(“201809”);
       Calendar  cal=Calendar.getInstance();
          cal.setTime(date);
            cal.add(cal.MONTH,-1);

              Date time = cal.getTime()

String endMonth = simDate.format(time);

得到的是月份减去一的

2.SimpleDateFormat s= new SimpleDateFormat("yyyy年MM月dd日");
        Date stDate= s.parse(date);
        SimpleDateFormat simDate= new SimpleDateFormat("yyyyMMdd");

        String format = simDate.format(stDate);

将2018年09月08日转换为20180908



猜你喜欢

转载自blog.csdn.net/bingguang1993/article/details/80372697