Java Timestamp setTimestamp(byte[] ba, int offset, Timestamp val)

Here you can find the source of setTimestamp(byte[] ba, int offset, Timestamp val)

Description

Put a Timestamp value "val" in a byte array "ba" starting at the offset "offset"

License

Open Source License

Parameter

Parameter Description
ba a parameter
offset a parameter
val a parameter

Declaration

public static void setTimestamp(byte[] ba, int offset, Timestamp val) 

Method Source Code


//package com.java2s;
/*// w w  w.  j ava2 s .  c  o m
 * DomUI Java User Interface - shared code
 * Copyright (c) 2010 by Frits Jalvingh, Itris B.V.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * See the "sponsors" file for a list of supporters.
 *
 * The latest version of DomUI and related code, support and documentation
 * can be found at http://www.domui.org/
 * The contact for the project is Frits Jalvingh <jal@etc.to>.
 */

import java.sql.*;

public class Main {
    /**
     * Put a Timestamp value "val" in a byte array "ba" starting at the offset "offset"
     *
     * @param ba
     * @param offset
     * @param val
     */
    public static void setTimestamp(byte[] ba, int offset, Timestamp val) {
        setLong(ba, offset, val == null ? 0 : val.getTime());
    }

    /**
     * Put a long value "val" in a byte array "ba" starting at the offset "offset"
     *
     * @param ba
     * @param offset
     * @param val
     */
    public static void setLong(byte[] ba, int offset, long val) {
        setInt(ba, offset, (int) val); // 4 bytes less significant
        setInt(ba, offset + 4, (int) (val >> 32)); // 4 bytes most significant
    }

    /**
     *
     */
    public static void setInt(byte[] ba, int offset, int val) {
        //      int ia[] = new int[4];
        int x;
        byte b;

        x = ((val >> 24) & 0xff);
        b = (byte) x;
        ba[offset] = b;

        x = ((val >> 16) & 0xff);
        b = (byte) x;
        ba[offset + 1] = b;

        x = ((val >> 8) & 0xff);
        b = (byte) x;
        ba[offset + 2] = b;

        x = (val & 0xff);
        b = (byte) x;
        ba[offset + 3] = b;
    }
}

Related

  1. removeTime(Timestamp ts)
  2. resetHourMinuteSecond(Timestamp timestamp, int hour, int minute, int second)
  3. roundToHour(Timestamp arg)
  4. roundToSecond(Timestamp t)
  5. safeTimestamp(Date value)
  6. setTimestamp(int index, Timestamp t, PreparedStatement stmt)
  7. setTimestampOrNull(PreparedStatement pstmt, int paramIndex, Timestamp value)
  8. sqlDate(Timestamp t)
  9. sqlDateConvertoStr(Timestamp date)