Administrator
2023-05-16 7a49155f41a11c93b692b120705432e04323cd1d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.fgkj.fbs5100;
 
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Calendar;
import java.util.Date;
 
 
public class FBS5100_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 Date time = new Date(0);
        
        public FBS5100_DateTime clone()
        {
            FBS5100_DateTime obj = new FBS5100_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 = FBS5100_ComBase.changeByteToInt(bf.get());
            month = FBS5100_ComBase.changeByteToInt(bf.get());
            day = FBS5100_ComBase.changeByteToInt(bf.get());
            hour = FBS5100_ComBase.changeByteToInt(bf.get());
            minute = FBS5100_ComBase.changeByteToInt(bf.get());
            second = FBS5100_ComBase.changeByteToInt(bf.get());
            
            time.setTime(getTimeInMillis());
        }
        
        public ByteBuffer getPCDateTimeBytes()
        {
            ByteBuffer bytebuffer = ByteBuffer.allocate(12);
            bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
            Calendar cad = Calendar.getInstance();
            //cad.set(23, 5, 10);
            bytebuffer.put(FBS5100_ComBase.changeIntToByte(cad.get(Calendar.YEAR)%100));
            bytebuffer.put(FBS5100_ComBase.changeIntToByte(cad.get(Calendar.MONTH)+1));
            bytebuffer.put(FBS5100_ComBase.changeIntToByte(cad.get(Calendar.DAY_OF_MONTH)));
            bytebuffer.put(FBS5100_ComBase.changeIntToByte(cad.get(Calendar.HOUR_OF_DAY)));
            bytebuffer.put(FBS5100_ComBase.changeIntToByte(cad.get(Calendar.MINUTE)));
            bytebuffer.put(FBS5100_ComBase.changeIntToByte(cad.get(Calendar.SECOND)));
            bytebuffer.flip();
            //System.out.println("设置时间:"+cad.get(Calendar.YEAR)+"-"+(cad.get(Calendar.MONTH)+1)+"-"+cad.get(Calendar.DAY_OF_MONTH)+" "+cad.get(Calendar.HOUR_OF_DAY)+":"+cad.get(Calendar.MINUTE)+":"+cad.get(Calendar.SECOND));
            return bytebuffer;
        }
        
        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 "FBS5100_DateTime [year=" + year + ", month=" + month + ", day=" + day + ", hour=" + hour
                    + ", minute=" + minute + ", second=" + second + ", time=" + time + "]";
        }
 
        
        
}