📄 yfpubs.java
字号:
lastWeekend = getNextDateByNum(currDate, -5);
}
else if (dayOfWeek == 6)
{
lastWeekend = getNextDateByNum(currDate, -6);
}
return lastWeekend;
}
/**
* 取当上周末工作日(五)日期:YYYYMMDD。
*
* @param
* @return String
* @author yufeng
*/
public static String getLastWeekendWorkday()
{
String lastWeekend = "";
int dayOfWeek = getWeekNumber();
String currDate = getSysDate();
if (dayOfWeek == 0)
{
lastWeekend = getNextDateByNum(currDate, -2);
}
else if (dayOfWeek == 1)
{
lastWeekend = getNextDateByNum(currDate, -3);
}
else if (dayOfWeek == 2)
{
lastWeekend = getNextDateByNum(currDate, -4);
}
else if (dayOfWeek == 3)
{
lastWeekend = getNextDateByNum(currDate, -5);
}
else if (dayOfWeek == 4)
{
lastWeekend = getNextDateByNum(currDate, -6);
}
else if (dayOfWeek == 5)
{
lastWeekend = getNextDateByNum(currDate, -7);
}
else if (dayOfWeek == 6)
{
lastWeekend = getNextDateByNum(currDate, -1);
}
return lastWeekend;
}
public static String getLastDayOfLastYear()
{
String sTemp = "";
String currYear = getSysDate().substring(0, 4);
int lastYear = Integer.parseInt(currYear) - 1;
sTemp = lastYear + "1231";
// System.out.println("lastyear="+sTemp);
return sTemp;
}
public static String getLastDayOfLastMonth()
{
Calendar calendar = new GregorianCalendar();
calendar.roll(Calendar.MONDAY, -1);
calendar.roll(Calendar.DATE, 0 - calendar.get(Calendar.DATE));
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String sTemp = sdf.format(calendar.getTime());
return sTemp;
}
/**
* 取当上月末工作日日期:YYYYMMDD。
*
* @param
* @return String
* @author yufeng
*/
public static String getLastWorkDayOfLastMonth() throws Exception
{
String lastMonthWorkDayEnd = "";
Calendar mycalendar = new GregorianCalendar();
mycalendar.roll(Calendar.MONDAY, -2);
mycalendar.roll(Calendar.DATE, 0 - mycalendar.get(Calendar.DATE));
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String lastMonthEndDay = sdf.format(mycalendar.getTime());
System.out.println("lastMonthEndDay=" + lastMonthEndDay);
java.util.Date d = sdf.parse(lastMonthEndDay);
Calendar cal = Calendar.getInstance();
cal.setTime(d);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
System.out.println("dayOfWeek=" + dayOfWeek);
if (dayOfWeek != 1 && dayOfWeek != 7)
return lastMonthEndDay;
if (dayOfWeek == 1)
{
lastMonthWorkDayEnd = getNextDateByNum(lastMonthEndDay, -2);
}
else if (dayOfWeek == 7)
{
lastMonthWorkDayEnd = getNextDateByNum(lastMonthEndDay, -1);
}
return lastMonthWorkDayEnd;
}
/**
* 取当上一工作日期:YYYYMMDD。
*
* @param
* @return String
* @author yufeng
*/
public static String getLastWorkDay() throws Exception
{
String lastWorkDay = "";
String currDay = getSysDate();
Calendar cal = Calendar.getInstance();
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
System.out.println("last dayOfWeek=" + dayOfWeek);
if (dayOfWeek == 2)
{
lastWorkDay = getNextDateByNum(currDay, -3);
}
else if (dayOfWeek == 1)
{
lastWorkDay = getNextDateByNum(currDay, -2);
}
else
{
lastWorkDay = getNextDateByNum(currDay, -1);
}
return lastWorkDay;
}
public String getGBDate(String date)
{
String yy = date.substring(0, 4);
String mm = date.substring(4, 6);
String dd = date.substring(6, 8);
return yy + "?" + mm + "?" + dd + "?";
}
/**
* 将YYYYMMDD形式的日期按DOT格式化:YYYY/MM/DD
*
* @param chDate
* String:YYYYMMDD形式的日期
* @param dot
* String:以此符号分隔
* @return String
* @author yufeng
*/
public static String getFormatDate(String chDate, String dot)
{
if (chDate.length() == 8)
return chDate.substring(0, 4) + dot + chDate.substring(4, 6) + dot
+ chDate.substring(6, 8);
else
return chDate;
}
/**
* 将将hhmmss形式的时间按DOT格式化:hh:mm:ss
*
* @param chTime
* String:hhmmss形式的时间
* @param dot
* String:以此符号分隔
* @return String
* @author yufeng
*/
public static String getFormatTime(String chTime, String dot)
{
if (chTime.length() == 6)
return chTime.substring(0, 2) + dot + chTime.substring(2, 4) + dot
+ chTime.substring(4, 6);
else
return chTime;
}
public boolean isNum(String sTemp)
{
byte[] bChar = sTemp.getBytes();
boolean bFlag = true;
for (int i = 0; i < sTemp.length(); i++)
{
if (bChar[i] < 48 || bChar[i] > 57)
{
bFlag = false;
break;
}
}
return bFlag;
}
public String format(int num, int len, String str)
{
String temp = new Integer(num).toString();
int j = temp.length();
for (int i = 0; i < len - j; i++)
{
temp = str + temp;
}
return temp;
}
public String[] split(String src, String s)
{
if (src == null || src.trim().equals(""))
{
String[] rt = new String[2];
rt[0] = src;
rt[1] = src;
return rt;
}
StringTokenizer st = null;
if (s == null || s.trim().equals(""))
st = new StringTokenizer(src);
else
st = new StringTokenizer(src, s);
String ret[] = new String[st.countTokens()];
int index = 0;
while (st.hasMoreTokens())
ret[index++] = st.nextToken();
return ret;
}
/**
* Code example: getNextDateByNum("20020131",5)? return 20020205;
*/
public static String getNextDateByNum(String currentDate, int iStep)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date date = sdf.parse(currentDate, new ParsePosition(0));// ?????????Date?
Calendar rightnow = Calendar.getInstance();
rightnow.setTime(date);
rightnow.add(Calendar.DATE, iStep);
date = rightnow.getTime();
currentDate = sdf.format(date);
return currentDate;
}
/**
* Code example: getNextDateByMonth("20020131",5)? return :20020630;
*/
public static String getNextDateByMonth(String currentDate, int iMouth)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date date = sdf.parse(currentDate, new ParsePosition(0));// ?????????Date?
Calendar rightnow = Calendar.getInstance();
rightnow.setTime(date);
rightnow.add(Calendar.MONTH, iMouth);
date = rightnow.getTime();
currentDate = sdf.format(date);
return currentDate;
}
public static String getSysTime()
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
String sTemp = sdf.format(Calendar.getInstance().getTime());
return sTemp;
}
public boolean dateValid(String strInput)
{
if (isNum(strInput) == false)
{
return false;
}
strInput = strInput.trim();
int iLen = strInput.length();
String strTmp;
if (iLen != 8)
{
return false;
}
int iYear;
strTmp = strInput.substring(0, 4);
iYear = Integer.parseInt(strTmp);
// test month
int iMonth;
strTmp = strInput.substring(4, 6);
iMonth = Integer.parseInt(strTmp);
if (iMonth > 12 || iMonth < 1)
{
return false;
}
int iDay;
strTmp = strInput.substring(6, 8);
iDay = Integer.parseInt(strTmp);
switch (iMonth)
{
case 4:
case 6:
case 9:
case 11:
if (iDay > 30)
{
return false;
}
break;
case 2:
if (iYear % 400 == 0 || (iYear % 100 != 0 && iYear % 4 == 0))
{
if (iDay > 29)
{
return false;
}
}
else if (iDay > 28)
{
return false;
}
}
if (iDay > 31 || iDay < 1)
{
return false;
}
return true;
}
public static String trim(String str)
{
if (str == null || str.equals("null") || str.length() == 0)
{
return "";
}
if (str.length() > 0)
{
return str.trim();
}
return str;
}
public static String fillBlankFront(String str, int length)
{
if (str.length() >= length)
{
System.out.println("string too long");
str = str.trim();
return str.substring(0, length);
}
str = str.trim();
int num = length - str.length();
for (int i = 0; i < num; i++)
{
str = " ".concat(str);
}
return str;
}
public static String fillBlankBack(String str, int length)
{
if (str.length() >= length)
{
System.out.println("string too long");
str = str.trim();
return str.substring(0, length);
}
str = str.trim();
int num = length - str.length();
for (int i = 0; i < num; i++)
{
str = str.concat(" ");
}
return str;
}
public static String ten2Hex(int i)
{
String str = "";
str = Integer.toHexString(i);
return str;
}
public static int hex2Ten(String s)
{
int sum = Integer.valueOf(s, 16).intValue();
return sum;
}
/*
* 功能:输入数组顺序不变,按原顺序返回数组中每一值由大排序的位置 输入:一个数组 输出:一个数组
*/
public static int[] getSort(double[] source) throws Exception
{
double[] source2 = new double[source.length];
for (int i = 0; i < source.length; i++)
{
source2[i] = source[i];
}
Arrays.sort(source2);
int[] target = new int[source.length];
for (int i = 0; i < source.length; i++)
{
for (int j = 0; j < source2.length; j++)
{
if (source[i] == source2[j])
{
target[i] = j + 1;
break;
}
}
}
return target;
}
public static String MD5Encrypt(String sInput) throws Exception
{
String algorithm = "";
// 输入不能为空
if (sInput.trim() == null || sInput.length() < 1)
{
throw new Exception("密码不能为空!!!");
}
// 取指定采用MD5算法
try
{
algorithm = System.getProperty("MD5.algorithm", "MD5");
System.out.println("algorithm=" + algorithm);// MD5
}
catch (SecurityException se)
{
throw new Exception("取指定采用MD5算法出错!!!");
}
// 定义MessageDigest对象
MessageDigest md = MessageDigest.getInstance(algorithm);
// 按照系统缺省的字符编码方式把sInput 转换成字节,并把结果存到一新的字节数组buffer中
byte buffer[] = sInput.getBytes();
// 从指定的字节数组buffer的偏移量0开始,用指定的字节数组修改由sInput生成摘要
// count为从 0 开始用的字节数长度。
for (int count = 0; count < sInput.length(); count++)
{
md.update(buffer, 0, count);
}
// 通过执行最后的诸如填充的操作完成散列码的计算,在调用之后复位该摘要
// 返回存放结果散列值的字节数组bDigest
byte bDigest[] = md.digest();
for (int i = 0; i < bDigest.length; i++)
System.out.print(bDigest[i]);
System.out.println("\n");
// 将bDigest转换为大整数bi,会出现负值即加密出的密码为33位。
// BigInteger bi=new BigInteger(bDigest);
// 返回bi字符串表示,即最终的编码结果
// return(bi.toString(16));
String after = byte2hex(bDigest);
return after;
}
// 二进制转十六进制字符串
public static String byte2hex(byte[] b)
{
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++)
{
stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
// if (n<b.length-1) hs=hs+":";
}
return hs.toUpperCase();
}
public static void findStr(String fileName, String str) throws Exception
{
String findStr = "[" + str + "]";
File aFile = new File(fileName);
if (!aFile.exists())
{
throw new FileNotFoundException("There is no file at " + fileName);
}
FileReader fileReader = new FileReader(aFile);
BufferedReader buffReader = new BufferedReader(fileReader);
String temp = null;
boolean f = false;
while ((temp = buffReader.readLine()) != null)
{
if (temp.equals(findStr))
{
f = true;
continue;
}
if (f)
{
if (temp == "" || temp.length() == 0)
break;
System.out.println(temp);
}
}
buffReader.close();
fileReader.close();
}
public static void main(String[] args)
{
try
{
YfPubs yfpubs = new YfPubs();
// String password=args[0];
String password = "123";
String afterEncrypt = "";
System.out.println("加密前密码:" + password);
afterEncrypt = yfpubs.MD5Encrypt(password);
System.out.println("加密后密码:" + afterEncrypt);
yfpubs.findStr("E:\\setup.sdb", "Bitmaps");
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -