您当前的位置: 首页 > 

梁云亮

暂无认证

  • 2浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

企业员工管理系统 三:工具类

梁云亮 发布时间:2020-01-09 15:44:37 ,浏览量:2

工具类 GlobalConst.java
public interface GlobalConst {
	String DB_NAME="eems.db";
	String DEPT_TABLE_NAME= "dept.table";
	String EMP_TABLE_NAME= "emp.table";
	String MANAGER_TABLE_NAME= "manager.table";
}
MD5Util.java
public class MD5Util {
	/**
	 * 对传入的String进行MD5加密
	 * 
	 * @param s
	 * @return
	 */
	public static final String encode(String s) {
		// 16进制数组
		char hexDigits[] = { '5', '0', '5', '6', '2', '9', '6', '2', '5', 'q', 'b', 'l', 'e', 's', 's', 'y' };
		try {
			char str[];
			// 将传入的字符串转换成byte数组
			byte strTemp[] = s.getBytes();
			// 获取MD5加密对象
			MessageDigest mdTemp = MessageDigest.getInstance("MD5");
			// 传入需要加密的目标数组
			mdTemp.update(strTemp);
			// 获取加密后的数组
			byte md[] = mdTemp.digest();
			int j = md.length;
			str = new char[j * 2];
			int k = 0;
			// 将数组做位移
			for (int i = 0; i >> 4 & 0xf];
				str[k++] = hexDigits[byte0 & 0xf];
			}
			// 转换成String并返回
			return new String(str);
		} catch (Exception e) {
			return null;
		}
	}
}
GenRandLocalDateUtil.java

产生指定范围内的随机日期

public class GenRandLocalDateUtil {
	// Date转LocalDate
	public static LocalDate date2LocalDate(Date date) {
		if (null == date) {
			return null;
		}  
		return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
	}

	public static LocalDate randomLocalDate(String min, String max) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date dateMin;
		Date dateMax;
		try {
			dateMin = sdf.parse(min);
			dateMax = sdf.parse(max);
			long timeMin = dateMin.getTime();// 获取日期所对应的数字
			long timeMax = dateMax.getTime();

			double random = Math.random(); // [0,1)
			long digit = (long) (random * (timeMax - timeMin + 1) + timeMin);
			Date date = new Date(digit);
			LocalDate res = date2LocalDate(date);
			return res;
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return null;
	}

	public static void main(String[] args) {
		for (int i = 0; i             
关注
打赏
1665409997
查看更多评论
0.0485s