Here you can find the source of toTimestampByHour(Date date, int hour)
public static Timestamp toTimestampByHour(Date date, int hour)
//package com.java2s; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Timestamp toTimestampByHour(Date date, int hour) { String h = Integer.toString(hour); if (h.length() == 1) h = "0" + h; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String now = sdf.format(date); String endDate = now + " " + h + ":00:00"; SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Timestamp timpestamp = null; try {/*from w w w. j a va 2s .c om*/ timpestamp = new Timestamp(sdf2.parse(endDate).getTime()); } catch (ParseException e) { e.printStackTrace(); } return timpestamp; } }