Tool.java~39~
资源名称:bangong.rar [点击查看]
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:4k
源码类别:
OA系统
开发平台:
Java
- package officeol.mc.tools;
- import java.security.NoSuchAlgorithmException;
- import java.security.MessageDigest;
- import java.util.Calendar;
- import java.util.GregorianCalendar;
- import java.util.Date;
- import java.io.UnsupportedEncodingException;
- public class Tool {
- private static String retmsg;
- public Tool() {
- }
- public String isNull(String s) {
- return s == null || (s != null && (s.equals("") || s.equals("null"))) ?
- " "
- : s.trim().replaceAll(" ", "");
- }
- public static String toGB(String iso) {
- try {
- return new String(iso.getBytes("ISO-8859-1"), "GB2312");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return iso;
- }
- public static String byte2hex(byte[] buf) {
- String str = "";
- String stmp = "";
- for (int n = 0; n < buf.length; n++) {
- stmp = (java.lang.Integer.toHexString(buf[n] & 0xFF));
- if (stmp.length() == 1) {
- str = str + "0" + stmp;
- } else {
- str = str + stmp;
- }
- }
- return str.toUpperCase();
- }
- public static String hash(String msg) {
- String t = msg;
- try {
- MessageDigest MD5 = MessageDigest.getInstance("MD5");
- MD5.update(msg.getBytes());
- byte[] hashvalue = MD5.digest();
- retmsg = byte2hex(hashvalue);
- t = retmsg;
- } catch (NoSuchAlgorithmException ex) {
- ex.printStackTrace();
- }
- return t;
- }
- public static String getTime() { //返回时间毫秒数
- Calendar c = new GregorianCalendar();
- c = Calendar.getInstance();
- return "" + c.getTimeInMillis();
- }
- public static String getTime1(String date, String hour) {
- //根据输入的日期(格式为YYYY-MM-DD)和小时返回该时间的毫秒数
- Calendar c = new GregorianCalendar();
- String[] day = date.split("-");
- c.set(Integer.parseInt(day[0]), Integer.parseInt(day[1])-1,
- Integer.parseInt(day[2]), Integer.parseInt(hour), 0);
- return "" + c.getTimeInMillis();
- }
- public static String getTime2(String timeMill) {
- //根据时间毫秒数返回日期及小时
- java.sql.Date da = new java.sql.Date(Long.parseLong(timeMill));
- String day = da.toString();
- String d[] = day.split("-");
- Calendar c = new GregorianCalendar();
- c.set(Integer.parseInt(d[0]),Integer.parseInt(d[1])-1,Integer.parseInt(d[2]),0,0);
- long hour = ( Long.parseLong(timeMill) - c.getTimeInMillis())/3600000l;
- //System.out.println("hour "+ hour);
- return "" + da.toString()+"-"+hour;
- }
- public static String getTime3(String timeMill) {
- //根据时间毫秒数返回日期及小时、分钟
- java.sql.Date da = new java.sql.Date(Long.parseLong(timeMill));
- String day = da.toString();
- String d[] = day.split("-");
- Calendar c = new GregorianCalendar();
- c.set(Integer.parseInt(d[0]),Integer.parseInt(d[1])-1,Integer.parseInt(d[2]),0,0);
- long hour = ( Long.parseLong(timeMill) - c.getTimeInMillis())/3600000l;
- long min = (Long.parseLong(timeMill) - hour * 3600000l)/60000l;
- System.out.println("min"+min);
- //System.out.println("hour "+ hour);
- return "" + da.toString()+"-"+hour;
- }
- public int getLogin(String username, String passport) {
- int b = -1; // -1错误 1正确
- DBConn dbc = new DBConn();
- String[][] rs = dbc.getArray(
- //从用户表中先择用户select count(*) from [user] where password='96E79218965EB72C92A549DD5A330112' and unmd5 = '7E58D63B60197CEB55A1C487989A3720'
- "select count(*) from [user] where password = '"
- + hash(isNull(passport)) + "' and unmd5 = '"
- + hash(username.trim()) + "'");
- if (rs != null && rs.length > 0) {
- if (rs[0][0] != null && !rs[0][0].equals("")) {
- if (Integer.parseInt(rs[0][0]) > 0) {
- return 1;
- }
- }
- }
- return b;
- }
- }