Convert into java.sql.Time into java.util.Calendar : Date Time Timestamp « Database « Java Tutorial

import java.sql.Time;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

 * Provides methods helpful in making object conversions not provided for by the
 * Sun or MyFaces distributions.
 * @author <a href="">Josh Holtzman</a>
public class ConversionUtil {

   * convert into java.sql.Time (or into java.util.Calendar
   * @param date
   *          The date containing the time.
   * @param am
   *          Whether this should be am (true) or pm (false)
   * @return
  public static Time convertDateToTime(Date date, boolean am) {
    if (date == null) {
      return null;

    Calendar cal = new GregorianCalendar();
    int hourOfDay = cal.get(Calendar.HOUR_OF_DAY);

    if (am) {
      // Check to make sure that the hours are indeed am hours
      if (hourOfDay > 11) {
        cal.set(Calendar.HOUR_OF_DAY, hourOfDay - 12);
    } else {
      // Check to make sure that the hours are indeed pm hours
      if (cal.get(Calendar.HOUR_OF_DAY) < 11) {
        cal.set(Calendar.HOUR_OF_DAY, hourOfDay + 12);
    return new Time(date.getTime());


20.20.Date Time Timestamp
20.20.1.Working with Date, Time, and Timestamp in JDBC
20.20.2.Insert Date value
20.20.3.Get Date value from ResultSet
20.20.4.Insert TIME value
20.20.5.Get TIME value from ResultSet
20.20.6.Insert TIMESTAMP value
20.20.7.Get TIMESTAMP value from ResultSet
20.20.8.Get the Current Date as a java.util.Date Object
20.20.9.Creating java.sql.Date Using java.util.Date
20.20.10.Creating java.sql.Date Using java.util.Calendar
20.20.11.Creating java.sql.Date Using the java.sql.Date.valueOf() Method
20.20.12.Creating java.sql.Date Using GregorianCalendar
20.20.13.Getting a Timestamp Object Using java.util.Date
20.20.14.Getting a Timestamp Object Using System.currentTimeMillis()
20.20.15.Get the Current Timestamp as a java.sql.Time Object?
20.20.16.Convert a String Date Such as 2003/01/10 to a java.sql.Date Object?
20.20.17.Convert a Timestamp to Month-Day-Year
20.20.18.Get a Date Label from a java.sql.Timestamp Object
20.20.19.Convert a java.sql.Timestamp Object to a java.util.Date Object?
20.20.20.Make a java.sql.Timestamp Object for a Given Year, Month, Day, Hour
20.20.21.Get a Date for a Specific Time Zone
20.20.22.Returns a java.sql.Timestamp equal to the current time
20.20.23.Convert into java.sql.Time into java.util.Calendar