不知道楼主的意思是不是说在当前的时间上减去相应的秒数后得到的结果,如果是的话可以这样做: Calendar calc = Calendar.getInstance(); calc.setTime(new Date()); calc.add(Calendar.SECOND,-30); Date date = calc.getTime();这样返回的date就是减去30秒后的结果
楼上的方法可以啊,JAVA获取当前时间 Data date=new Date()然后转换成Calendar格式 减去30 在转会data格式就可以了
Date currentDate = new Date(); Date result = new Date(currentDate.getTime() - 30 * 1000) testcodeDate currentDate = new Date(); SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); System.out.println(format.format(currentDate)); System.out.println(format.format(new Date(currentDate.getTime() - 30 * 1000)));
calc.setTime(new Date());
calc.add(Calendar.SECOND,-30);
Date date = calc.getTime();这样返回的date就是减去30秒后的结果
Date result = new Date(currentDate.getTime() - 30 * 1000)
testcodeDate currentDate = new Date();
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
System.out.println(format.format(currentDate));
System.out.println(format.format(new Date(currentDate.getTime() - 30 * 1000)));