Java ByteBuffer Set setCreationTime(ByteBuffer buf, Date date)

Here you can find the source of setCreationTime(ByteBuffer buf, Date date)

Description

Set the creation date.

License

Open Source License

Parameter

Parameter Description
buf The buffer to write into. It must have been properly positioned beforehand.
date The date to set.

Declaration

public static void setCreationTime(ByteBuffer buf, Date date) 

Method Source Code

//package com.java2s;
/*/* w w  w.  j  a v a 2s  . co m*/
 * Copyright (C) 2006 Steve Ratcliffe
 * 
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 * 
 *  This program 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 General Public License for more details.
 * 
 * 
 * Author: Steve Ratcliffe
 * Create date: 03-Dec-2006
 */

import java.nio.ByteBuffer;

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**
     * Set the creation date.  Note that the year is encoded specially.
     *
     * @param buf The buffer to write into.  It must have been properly positioned
     * beforehand.
     * @param date The date to set.
     */
    public static void setCreationTime(ByteBuffer buf, Date date) {
        Calendar cal = Calendar.getInstance();

        if (date != null)
            cal.setTime(date);

        fillBufFromTime(buf, cal);
    }

    private static void fillBufFromTime(ByteBuffer buf, Calendar cal) {
        buf.putChar((char) cal.get(Calendar.YEAR));
        buf.put((byte) (cal.get(Calendar.MONTH) + 1));
        buf.put((byte) cal.get(Calendar.DAY_OF_MONTH));
        buf.put((byte) cal.get(Calendar.HOUR_OF_DAY));
        buf.put((byte) cal.get(Calendar.MINUTE));
        buf.put((byte) cal.get(Calendar.SECOND));
    }
}

Related

  1. set24BitInt(ByteBuffer buffer, int value)
  2. setBatch(ByteBuffer bb, long batchId)
  3. setByteOrder(ByteBuffer buffer)
  4. setBytesAtOffset(ByteBuffer buffer, int offset, int length, byte[] data)
  5. setCell(ByteBuffer buffer, int cellIndex, int cellbytes)
  6. setFree(int frameIx, int offset, boolean free, ByteBuffer[] frames)
  7. setLimIfNeeded(ByteBuffer bb, int lim)
  8. setLong(ByteBuffer buffer, long data)
  9. setSByte(ByteBuffer buffer, byte data)