Java对String类型的时间进行加减操作
程序员文章站
2022-03-04 19:07:04
...
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()));