Here you can find the source of plusOrMinusHours(Date dateTime, long count)
public static String plusOrMinusHours(Date dateTime, long count)
//package com.java2s; /*//from ww w .j a v a 2 s. c o m * @(#)CommonUtils.java Jun 30, 2009 * * Copyright 2008 by ChinanetCenter Corporation. * * All rights reserved. * * This software is the confidential and proprietary information of * ChinanetCenter Corporation ("Confidential Information"). You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with ChinanetCenter. * */ import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String plusOrMinusHours(Date dateTime, long count) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateTime.setTime(dateTime.getTime() + count * 3600000); return sdf.format(dateTime); } catch (Exception e) { e.printStackTrace(); return ""; } } public static String plusOrMinusHours(String dateTime, long count) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = sdf.parse(dateTime); date.setTime(date.getTime() + count * 3600000); return sdf.format(date); } catch (Exception e) { e.printStackTrace(); return ""; } } }