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()));
————————————————
版权声明:本文为CSDN博主「hadoove」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u013817676/article/details/93115321

posted on 2019-09-24 13:26  带镐伤的土豆  阅读(1291)  评论(0编辑  收藏  举报

导航