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()));