java 获取指定小时前后

public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
         calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 10);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("一个小时前:" + df.format(calendar.getTime()));
        System.out.println("当前的时间:" + df.format(new Date()));

    }

 

posted @ 2015-11-05 09:44  wind90  阅读(765)  评论(0编辑  收藏  举报