FileDocCategorySizeDatePackage
SystemTimeUtils.javaAPI DocApache Poi 3.0.13908Sun Mar 11 12:59:30 GMT 2007org.apache.poi.hslf.util

SystemTimeUtils

public class SystemTimeUtils extends Object
A helper class for dealing with SystemTime Structs, as defined at http://msdn.microsoft.com/library/en-us/sysinfo/base/systemtime_str.asp . Discrepancies between Calendar and SYSTEMTIME: - that January = 1 in SYSTEMTIME, 0 in Calendar. - that the day of the week (0) starts on Sunday in SYSTEMTIME, and Monday in Calendar It is also the case that this does not store the timezone, and no... it is not stored as UTC either, but rather the local system time (yuck.)
author
Daniel Noll
author
Nick Burch

Fields Summary
Constructors Summary
Methods Summary
public static java.util.DategetDate(byte[] data)
Get the date found in the byte array, as a java Data object

		return getDate(data,0);
	
public static java.util.DategetDate(byte[] data, int offset)
Get the date found in the byte array, as a java Data object

        Calendar cal = new GregorianCalendar();
        
        cal.set(Calendar.YEAR,         LittleEndian.getShort(data,offset));
        cal.set(Calendar.MONTH,        LittleEndian.getShort(data,offset+2)-1);
        // Not actually needed - can be found from day of month 
        //cal.set(Calendar.DAY_OF_WEEK,  LittleEndian.getShort(data,offset+4)+1);
        cal.set(Calendar.DAY_OF_MONTH, LittleEndian.getShort(data,offset+6));
        cal.set(Calendar.HOUR_OF_DAY,  LittleEndian.getShort(data,offset+8));
        cal.set(Calendar.MINUTE,       LittleEndian.getShort(data,offset+10));
        cal.set(Calendar.SECOND,       LittleEndian.getShort(data,offset+12));
        cal.set(Calendar.MILLISECOND,  LittleEndian.getShort(data,offset+14));

        return cal.getTime();
	
public static voidstoreDate(java.util.Date date, byte[] dest)
Convert the supplied java Date into a SystemTime struct, and write it into the supplied byte array.

		storeDate(date, dest, 0);
	
public static voidstoreDate(java.util.Date date, byte[] dest, int offset)
Convert the supplied java Date into a SystemTime struct, and write it into the supplied byte array.

        Calendar cal = new GregorianCalendar();
        cal.setTime(date);

        LittleEndian.putShort(dest, offset + 0, (short) cal.get(Calendar.YEAR));
        LittleEndian.putShort(dest, offset + 2, (short)(cal.get(Calendar.MONTH) + 1));
        LittleEndian.putShort(dest, offset + 4, (short)(cal.get(Calendar.DAY_OF_WEEK)-1));
        LittleEndian.putShort(dest, offset + 6, (short) cal.get(Calendar.DAY_OF_MONTH));
        LittleEndian.putShort(dest, offset + 8, (short) cal.get(Calendar.HOUR_OF_DAY));
        LittleEndian.putShort(dest, offset + 10,(short) cal.get(Calendar.MINUTE));
        LittleEndian.putShort(dest, offset + 12,(short) cal.get(Calendar.SECOND));
        LittleEndian.putShort(dest, offset + 14,(short) cal.get(Calendar.MILLISECOND));