首页 > 代码库 > Java实现当前时间加减小时(年,月,日,小时,分钟)

Java实现当前时间加减小时(年,月,日,小时,分钟)

        String oneHoursAgoTime="";
        Date dt = new Date();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd-HH");
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(dt);
        //rightNow.add(Calendar.DATE, -1);
        rightNow.add(Calendar.HOUR, -1);
        Date dt1=rightNow.getTime();
        oneHoursAgoTime = sdf.format(dt1);
        return oneHoursAgoTime;

Java实现当前时间加减小时(年,月,日,小时,分钟)