Java Timestamp Convert To timeStampToBytes(Timestamp ts)

Here you can find the source of timeStampToBytes(Timestamp ts)

Description

time Stamp To Bytes

License

Apache License

Declaration

public static byte[] timeStampToBytes(Timestamp ts) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.Timestamp;
import java.util.Calendar;

public class Main {
    public static byte[] timeStampToBytes(Timestamp ts) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(ts);//from   w  w w  . j ava 2 s .c o  m

        byte[] b = new byte[12];
        b[0] = (byte) 0;
        b[1] = (byte) (cal.get(Calendar.YEAR) & 0xff);
        b[2] = (byte) (cal.get(Calendar.YEAR) >>> 8);
        b[3] = (byte) (cal.get(Calendar.MONTH) & 0xff);
        b[4] = (byte) (cal.get(Calendar.DATE) & 0xff);
        b[5] = (byte) (cal.get(Calendar.HOUR) & 0xff);
        b[6] = (byte) (cal.get(Calendar.MINUTE) & 0xff);
        b[7] = (byte) (cal.get(Calendar.SECOND) & 0xff);
        b[8] = (byte) (ts.getNanos() & 0xff);
        b[9] = (byte) (ts.getNanos() >>> 8);
        b[10] = (byte) (ts.getNanos() >>> 16);
        b[11] = (byte) (ts.getNanos() >>> 24);
        return b;
    }
}

Related

  1. timestamp2Date(java.sql.Timestamp t)
  2. timestamp2Internal(java.sql.Timestamp t)
  3. timestamp2ToTimestamp(long seconds, int fraction, int width)
  4. timestampSqlToDate(Timestamp timestamp)
  5. TimestampToBigint(String timestamp)
  6. timestampToCalendar(java.sql.Timestamp inTime)
  7. timestampToCalendar(Timestamp time)
  8. TimestampToDate(Integer time)
  9. timestampToDate(java.sql.Timestamp ts)