Date now = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//可以方便地修改日期格式 String time = dateFormat.format( now ); Log.i("kk",":::"+time ); Date dNow = new Date(); //当前时间 Date dBefore = new Date(); Calendar calendar = Calendar.getInstance(); //得到日历 calendar.setTime(dNow);//把当前时间赋给日历 calendar.add(calendar.MONTH, -3); //设置为前3月 dBefore = calendar.getTime(); //得到前3月的时间 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); //设置时间格式 String defaultStartDate = sdf.format(dBefore); //格式化前3月的时间 String defaultEndDate = sdf.format(dNow); //格式化当前时间 Log.i("kk","前3个月的时间是:" + defaultStartDate); Log.i("kk","生成的时间是:" + defaultEndDate);