田源
2024-03-07 4b4083fd73dc27ece42f4835483565eef0e4f608
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
package com.vci.client.uif.engine.client.compare.tools;
 
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
 
/**
 * 常用工具类
 * @author VCI-STGK006
 *
 */
public class CompareTools {
 
    /**
     * 数字类型是否一致校验
     * @param num1 数字1
     * @param num2 数字2
     * @return 如果两个数字都为空返回true
     */
    public static boolean validateNumber(String num1, String num2){
        if(num1 == null) {
            num1 = "";
        }
        if(num2 == null) {
            num2 = "";
        }
        boolean temp = true;
        if(!num2.equals(num1)){
            //如果不一致还需判断是否是数字格式不一致导致
            if(!num1.equals("") && !num2.equals("")){
                try{
                    double dNum1 = Double.parseDouble(num1);
                    double dNum2 = Double.parseDouble(num2);
                    if(dNum1 != dNum2){
                        temp = false;
                    }
                } catch(Exception e){
                    temp = false;
                }
            } else {
                return false;
            }
        }
        return temp;
    }
    
    /**
     * 得到去空字符串
     * @param str
     * @return
     */
    public static String getString(String str) {
        if(str == null) {
            return "";
        }
        return str.trim();
    }
    
    /**
     * 获得当前时间字符串
     * @return
     */
    public static String getSysDateTs() {
        Date now = Calendar.getInstance().getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String nowStr = sdf.format(now);
        return nowStr + ".00";
    }
    
    /**
     * 获得当前时间字符串
     * @return
     */
    public static String getSysDate() {
        Date now = Calendar.getInstance().getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String nowStr = sdf.format(now);
        return nowStr;
    }
}