String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; Date dNow = new Date(); //当前时间 Date dBefore = new Date(); Calendar calendar = Calendar.getInstance(); //得到日历 calendar.setTime(dNow);//把当前时间赋给日历 calendar.add(Calendar.DAY_OF_MONTH, -1); //设置为前一天 dBefore = calendar.getTime(); //得到前一天的时间 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置时间格式 String defaultStartDate = sdf.format(dBefore); //格式化前一天 String defaultEndDate = sdf.format(dNow); //格式化当前时间 System.out.println("前一天的时间是:" + defaultStartDate); System.out.println("生成的时间是:" + defaultEndDate);
Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -1); //得到前一天 Date date = calendar.getTime(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(df.format(date));
时间: 2024-10-12 19:47:22