`
刘金剑
  • 浏览: 145330 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Java 返回一个日期一个小时候的日期值

    博客分类:
  • Java
阅读更多
public static String addDate(String day, int x) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 24小时制
		// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd
		// hh:mm:ss");//12小时制
		Date date = null;
		try {
			date = format.parse(day);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		if (date == null)
			return "";
		System.out.println("front:" + format.format(date));
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.HOUR_OF_DAY, x);// 24小时制
		// cal.add(Calendar.HOUR, x);12小时制
		date = cal.getTime();
		cal = null;
		return format.format(date);
	}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics