Java SQL Date Convert dateToBytes(Date d)

Here you can find the source of dateToBytes(Date d)

Description

date To Bytes

License

Apache License

Declaration

public static byte[] dateToBytes(Date d) 

Method Source Code

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

import java.sql.Date;

import java.util.Calendar;

public class Main {
    public static byte[] dateToBytes(Date d) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);/*w  w  w  . ja v a2 s  . com*/

        byte[] b = new byte[5];
        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);
        return b;
    }
}

Related

  1. dateToBeginOfDay(Date data)
  2. dateToCalendar(Date input)
  3. dateToInternal(java.sql.Date date)
  4. dateToLong(Date date)
  5. dateToSql(Date dat)