Here you can find the source of getBothTime(String startTime, int hours)
public static String getBothTime(String startTime, int hours)
//package com.java2s; //License from project: LGPL import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String getBothTime(String startTime, int hours) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try {/* w ww.j a v a 2s . c o m*/ Date date = sdf.parse(startTime); Date retDate = new Date(date.getTime() + hours * 3600000l); return sdf.format(retDate); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }