Java SQL Time Create getTimeBy(int hour)

Here you can find the source of getTimeBy(int hour)

Description

get Time By

License

Open Source License

Declaration

public static Timestamp getTimeBy(int hour) 

Method Source Code


//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;
    }
}

Related

  1. getTime(Object value, int columnType)
  2. getTime(ResultSet resultSet, String columnName)
  3. getTime(ResultSet rs, String column)
  4. getTime(String time)
  5. getTimeAndDateStamp(String line)
  6. getTimeFormat()
  7. getTimeFromCalendar(final Calendar calendar)
  8. getTimeList(ResultSet resultSet, String columnName)
  9. getTimeLong(ResultSet resultSet)