mxpopstar
2022-05-03 e75ef5f04f61aa5fbd89fd5c413dcee1819b7a91
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.dev.ntm.data.idc;
 
import java.util.Date;
import java.util.GregorianCalendar;
 
import com.dev.ntm.data.fbo.FboTestTime;
 
public class IdcTestTime {
    public int year;
    public int month;
    public int dayofweek;
    public int day;
    public int hour;
    public int minute;
    public int second;
    public int millsecond;
    
    public long getTimeInSecond()
    {
        GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
        gc.set(GregorianCalendar.YEAR, year);
        gc.set(GregorianCalendar.MONTH, month-1);
        gc.set(GregorianCalendar.DATE, day);
        gc.set(GregorianCalendar.HOUR_OF_DAY, hour);
        gc.set(GregorianCalendar.MINUTE, minute);
        gc.set(GregorianCalendar.SECOND, second);
        
        return (gc.getTimeInMillis()/1000);
    }
    
    public static Date getDateFromStr(String str_time)
    {
        GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance(); 
        int year = 1, month = 1, day = 1, hour = 0, minute = 0, second = 0;
        
        String str = str_time;
        
        if(str.indexOf("-") >= 0) {
            year = Integer.parseInt(str.substring(0, str.indexOf("-")).trim());
            str = str.substring(str.indexOf("-")+1, str.length());
            month = Integer.parseInt(str.substring(0, str.indexOf("-")).trim());
            str = str.substring(str.indexOf("-")+1, str.length());
        } else if(str.indexOf("/") >= 0) {
            year = Integer.parseInt(str.substring(0, str.indexOf("/")).trim());
            str = str.substring(str.indexOf("/")+1, str.length());
            month = Integer.parseInt(str.substring(0, str.indexOf("/")).trim());
            str = str.substring(str.indexOf("/")+1, str.length());
        }
        
        if(str.indexOf(" ") >= 0) {
            day = Integer.parseInt(str.substring(0, str.indexOf(" ")).trim());
            str = str.substring(str.indexOf(" ")+1, str.length()).trim();
        } else {
            day = Integer.parseInt(str.trim());
            str = str.trim();
        }
        
        if(year < day) {
            int tmp = year;
            year = day;
            day = tmp;
        }
        
        if(str.indexOf(" ") >= 0) {
            str = str.substring(str.indexOf(" ")+1, str.length());
        }
        if(str.indexOf(":") >= 0) {
            hour = Integer.parseInt(str.substring(0, str.indexOf(":")).trim());
            if(str_time.contains("ÏÂÎç")) {
                if(hour < 12) {
                    hour += 12;
                }
            }
            str = str.substring(str.indexOf(":")+1, str.length());
            
            minute = Integer.parseInt(str.substring(0, str.indexOf(":")).trim());
            str = str.substring(str.indexOf(":")+1, str.length());
            
            second = Integer.parseInt(str.trim());
        }
        
        gc.set(GregorianCalendar.YEAR, year-2000);
        gc.set(GregorianCalendar.MONTH, month);
        gc.set(GregorianCalendar.DATE, day);
        gc.set(GregorianCalendar.HOUR_OF_DAY, hour);
        gc.set(GregorianCalendar.MINUTE, minute);
        gc.set(GregorianCalendar.SECOND, second);
        
        return gc.getTime();
    }
    
    public static FboTestTime getFboTestTime(IdcTestTime t_end, IdcTestTime t_begin)
    {
        FboTestTime fbo_time = new FboTestTime();
        long seconds = t_end.getTimeInSecond() - t_begin.getTimeInSecond();
        fbo_time.hour = (int) (seconds / 3600);
        fbo_time.minute = (int) ((seconds % 3600) / 60);
        fbo_time.second = (int) (seconds % 60);
        
        return fbo_time;
    }
}