package com.dev.bts.data;
|
|
import java.nio.ByteBuffer;
|
import java.nio.ByteOrder;
|
import java.util.Calendar;
|
|
public class FBS9100_DateTime
|
{
|
public int year = 0;
|
public int month = 1;
|
public int day = 1;
|
public int hour = 0;
|
public int minute = 0;
|
public int second = 0;
|
|
public FBS9100_DateTime clone()
|
{
|
FBS9100_DateTime obj = new FBS9100_DateTime();
|
|
obj.year = year;
|
obj.month = month;
|
obj.day = day;
|
obj.hour = hour;
|
obj.minute = minute;
|
obj.second = second;
|
|
return obj;
|
}
|
|
public void putByteBuffer(final ByteBuffer bf)
|
{
|
year = FBS9100_ComBase.changeByteToInt(bf.get());
|
month = FBS9100_ComBase.changeByteToInt(bf.get());
|
day = FBS9100_ComBase.changeByteToInt(bf.get());
|
hour = FBS9100_ComBase.changeByteToInt(bf.get());
|
minute = FBS9100_ComBase.changeByteToInt(bf.get());
|
second = FBS9100_ComBase.changeByteToInt(bf.get());
|
}
|
|
public ByteBuffer getPCDateTimeBytes()
|
{
|
ByteBuffer bytebuffer = ByteBuffer.allocate(12);
|
bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
|
Calendar cad = Calendar.getInstance();
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(cad.get(Calendar.YEAR)%100));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(cad.get(Calendar.MONTH)+1));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(cad.get(Calendar.DAY_OF_MONTH)));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(cad.get(Calendar.HOUR_OF_DAY)));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(cad.get(Calendar.MINUTE)));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(cad.get(Calendar.SECOND)));
|
bytebuffer.flip();
|
|
return bytebuffer;
|
}
|
|
public String getDateTimeStr() {
|
return String.format("%04d-%02d-%02d %02d:%02d:%02d",
|
year+2000, month, day, hour, minute, second);
|
}
|
|
public long getTimeInMillis() {
|
Calendar ca = Calendar.getInstance();
|
int month_t = month;
|
if(month_t > 0) {
|
month_t -= 1;
|
}
|
ca.set(year+2000, month_t, day, hour, minute, second);
|
|
return ca.getTimeInMillis();
|
}
|
|
@Override
|
public String toString() {
|
return "FBS9100_DateTime [year=" + year + ", month=" + month + ", day=" + day + ", hour=" + hour + ", minute="
|
+ minute + ", second=" + second + "]";
|
}
|
}
|
/***************************************************************************************
|
*************************** end of file (FBS_DateTime) *********************************
|
***************************************************************************************/
|