Here you can find the source of setCreationTime(ByteBuffer buf, Date date)
Parameter | Description |
---|---|
buf | The buffer to write into. It must have been properly positioned beforehand. |
date | The date to set. |
public static void setCreationTime(ByteBuffer buf, Date date)
//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)); } }