Here you can find the source of getTimeBy(int hour)
public static Timestamp getTimeBy(int hour)
//package com.java2s; //License from project: Open Source License import java.sql.Timestamp; import java.util.Calendar; public class Main { public static Timestamp getTimeBy(int hour) { return getTimeBy(hour, 0, 0, 0); }//from w w w. j a va 2 s.c o m public static Timestamp getTimeBy(int hour, int minute, int second, int millisecond) { Calendar calendar = getCalendar(); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, second); calendar.set(Calendar.MILLISECOND, millisecond); return new Timestamp(calendar.getTimeInMillis()); } public static Calendar getCalendar() { return getCalendar(null); } public static Calendar getCalendar(Integer year) { return getCalendar(year, null, null); } public static Calendar getCalendar(Integer year, Integer month) { return getCalendar(year, month, null); } public static Calendar getCalendar(Integer year, Integer month, Integer date) { Calendar calendar = Calendar.getInstance(); if (year != null) calendar.set(Calendar.YEAR, year); if (month != null) calendar.set(Calendar.MONTH, month - 1); if (date != null) calendar.set(Calendar.DAY_OF_MONTH, date); return calendar; } }