Example usage for java.sql Timestamp getHours

List of usage examples for java.sql Timestamp getHours

Introduction

In this page you can find the example usage for java.sql Timestamp getHours.

Prototype

@Deprecated
public int getHours() 

Source Link

Document

Returns the hour represented by this Date object.

Usage

From source file:com.dc.gameserver.extComponents.Kit.DateUtil.java

/**
 * ???//from   w  ww. ja  v a  2  s.  co m
 * 8? 12? 19? 21?
 * @param lastTime
 * @param nowTime
 * @return
 */
@SuppressWarnings("deprecation")
public static boolean getFreeActPoint(Timestamp lastTime, Timestamp nowTime) {
    int lastTimeCount = lastTime.getHours() * 60 + lastTime.getMinutes();
    int nowTimeCount = nowTime.getHours() * 60 + nowTime.getMinutes();
    int count1 = 8 * 60 + 30;
    int count2 = 12 * 60 + 30;
    int count3 = 19 * 60 + 30;
    //?
    if (lastTime.getDate() == nowTime.getDate()) {
        if (lastTimeCount >= count3) {
            return false;
        } else if (lastTimeCount < count1)
            return nowTimeCount >= count1;
        else if (lastTimeCount >= count1 && lastTimeCount < count2) {
            return nowTimeCount >= count2;
        } else if (lastTimeCount >= count2 && lastTimeCount < count3) {
            return nowTimeCount >= count3;
        }
    } else {
        if (lastTimeCount >= count3) {
            return nowTimeCount >= count1;
        }
    }
    return true;
}

From source file:com.dc.gameserver.extComponents.Kit.DateUtil.java

/**
 * //from   ww  w  .j a  v  a2s.  c  o  m
 * 5
 * @param lastTime
 * @param nowTime
 * @return
 */
@SuppressWarnings("deprecation")
public static int getDay(Timestamp lastTime, Timestamp nowTime) {
    if (nowTime == null)
        nowTime = new Timestamp(System.currentTimeMillis());
    if (lastTime == null)
        return 1;
    if (lastTime.getHours() < 5) {
        // 1-3
        if (nowTime.getHours() < 5) {
            return getDiffDay(nowTime, lastTime);
            // 1-4
        } else {
            return getDiffDay(nowTime, lastTime) + 1;
        }
    } else {
        //2-3
        if (nowTime.getHours() < 5) {
            return getDiffDay(nowTime, lastTime) - 1;
            //2-4
        } else {
            return getDiffDay(nowTime, lastTime);
        }
    }
}

From source file:com.google.visualization.datasource.util.SqlDataSourceHelper.java

/**
 * Creates a table cell from the value in the current row of the given result
 * set and the given column index. The type of the value is determined by the
 * given value type.//from w ww .j  a v a  2 s. c o  m
 *
 * @param rs The result set holding the data from the sql table. The result
 *     points to the current row.
 * @param valueType The value type of the column that the cell belongs to.
 * @param column The column index. Indexes are 0-based.
 *
 * @return The table cell.
 *
 * @throws SQLException Thrown when the connection to the database failed.
 */
private static TableCell buildTableCell(ResultSet rs, ValueType valueType, int column) throws SQLException {
    Value value = null;

    // SQL indexes are 1- based.
    column = column + 1;

    switch (valueType) {
    case BOOLEAN:
        value = BooleanValue.getInstance(rs.getBoolean(column));
        break;
    case NUMBER:
        value = new NumberValue(rs.getDouble(column));
        break;
    case DATE:
        Date date = rs.getDate(column);
        // If date is null it is handled later.
        if (date != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the year, month and date in the gregorian calendar.
            // Use the 'set' method with those parameters, and not the 'setTime'
            // method with the date parameter, since the Date object contains the
            // current time zone and it's impossible to change it to 'GMT'.
            gc.set(date.getYear() + 1900, date.getMonth(), date.getDate());
            value = new DateValue(gc);
        }
        break;
    case DATETIME:
        Timestamp timestamp = rs.getTimestamp(column);
        // If timestamp is null it is handled later.
        if (timestamp != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the year, month, date, hours, minutes and seconds in the
            // gregorian calendar. Use the 'set' method with those parameters,
            // and not the 'setTime' method with the timestamp parameter, since
            // the Timestamp object contains the current time zone and it's
            // impossible to change it to 'GMT'.
            gc.set(timestamp.getYear() + 1900, timestamp.getMonth(), timestamp.getDate(), timestamp.getHours(),
                    timestamp.getMinutes(), timestamp.getSeconds());
            // Set the milliseconds explicitly, as they are not saved in the
            // underlying date.
            gc.set(Calendar.MILLISECOND, timestamp.getNanos() / 1000000);
            value = new DateTimeValue(gc);
        }
        break;
    case TIMEOFDAY:
        Time time = rs.getTime(column);
        // If time is null it is handled later.
        if (time != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the hours, minutes and seconds of the time in the gregorian
            // calendar. Set the year, month and date to be January 1 1970 like
            // in the Time object.
            // Use the 'set' method with those parameters,
            // and not the 'setTime' method with the time parameter, since
            // the Time object contains the current time zone and it's
            // impossible to change it to 'GMT'.
            gc.set(1970, Calendar.JANUARY, 1, time.getHours(), time.getMinutes(), time.getSeconds());
            // Set the milliseconds explicitly, otherwise the milliseconds from
            // the time the gc was initialized are used.
            gc.set(GregorianCalendar.MILLISECOND, 0);
            value = new TimeOfDayValue(gc);
        }
        break;
    default:
        String colValue = rs.getString(column);
        if (colValue == null) {
            value = TextValue.getNullValue();
        } else {
            value = new TextValue(rs.getString(column));
        }
        break;
    }
    // Handle null values.
    if (rs.wasNull()) {
        return new TableCell(Value.getNullValueFromValueType(valueType));
    } else {
        return new TableCell(value);
    }
}