Java对String类型的时间进行加减操作

String time = "2018-08-04 02:30:00";
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        
Calendar calendar = Calendar.getInstance();
try {
    calendar.setTime(df.parse(time));
} catch (ParseException e) {
    // TODO Auto-generated catch block
     e.printStackTrace();
}
calendar.add(Calendar.SECOND, -30);
System.out.println(df.format(calendar.getTime()));

 

你可能感兴趣的:(java)