houzhongjian
2024-11-06 7412dd652c0ac48c5a17b5d9b61d5d2a0f686137
提交 | 用户 | 时间
149dd0 1 package com.iailab.netsdk.lib.structure;
H 2
3 import com.iailab.netsdk.lib.NetSDKLib;
4
5 import java.util.Calendar;
6 import java.util.Date;
7
8 /**
9  * 时间
10  *
11  * @author 47081
12  */
13 public class NET_TIME extends NetSDKLib.SdkStructure {
14   /** 年 */
15   public int dwYear;
16   /** 月 */
17   public int dwMonth;
18   /** 日 */
19   public int dwDay;
20   /** 时 */
21   public int dwHour;
22   /** 分 */
23   public int dwMinute;
24   /** 秒 */
25   public int dwSecond;
26
27   public NET_TIME() {
28     super();
29   }
30
31   public NET_TIME(int dwYear, int dwMonth, int dwDay, int dwHour, int dwMinute, int dwSecond) {
32     this.dwYear = dwYear;
33     this.dwMonth = dwMonth;
34     this.dwDay = dwDay;
35     this.dwHour = dwHour;
36     this.dwMinute = dwMinute;
37     this.dwSecond = dwSecond;
38   }
39
40   /**
41    * 字符串解析时间
42    *
43    * @param date 时间字符串,举例2020/5/20/12/20/34
44    */
45   public NET_TIME(String date) {
46     String[] dates = date.split("/");
47     this.dwYear = Integer.parseInt(dates[0]);
48     this.dwMonth = Integer.parseInt(dates[1]);
49     this.dwDay = Integer.parseInt(dates[2]);
50     this.dwHour = Integer.parseInt(dates[3]);
51     this.dwMinute = Integer.parseInt(dates[4]);
52     this.dwSecond = Integer.parseInt(dates[5]);
53   }
54
55   // 用于列表中显示
56   public String toStringTime() {
57     return String.format(
58         "%02d/%02d/%02d %02d:%02d:%02d", dwYear, dwMonth, dwDay, dwHour, dwMinute, dwSecond);
59   }
60
61   public String toStringTimeEx() {
62     return String.format(
63         "%02d-%02d-%02d %02d:%02d:%02d", dwYear, dwMonth, dwDay, dwHour, dwMinute, dwSecond);
64   }
65
66   public String toString() {
67     return String.format(
68         "%02d%02d%02d%02d%02d%02d", dwYear, dwMonth, dwDay, dwHour, dwMinute, dwSecond);
69   }
70
71   public Date toDate() {
72     Calendar instance = Calendar.getInstance();
73     instance.set(this.dwYear, this.dwMonth, this.dwDay, this.dwHour, this.dwMinute, this.dwSecond);
74     return instance.getTime();
75   }
76 }