07-22:学习base64的加密和解密,求几天前的日期和求两日期的间隔天数,解决jexl读取合并单元格的数据问题
base64问题:base64在java有类封装好方法,sun.misc.BASE64Decoder和sun.misc.BASE64Encoder可用于base64的解密和加密。
例子如下:
BASE64Decoder decoder = new BASE64Decoder();
BASE64Encoder encoder = new BASE64Encoder();
String cryptograph = "NTM0NzYwNzE";
String originText = "534760710";
try{
byte[] buffer = decoder.decodeBuffer(cryptograph);
System.out.println(new String(buffer));
String codeStr = encoder.encode(originText.getBytes());
System.out.println(codeStr);
}catch(Exception e){
e.printStackTrace();
}
jexl读取excel问题:原来我在移动的网上下载了最近5个月的通讯记录,我手机丢了,所以想把所有号码提取出来记录,但在下载的excel表 里有很多重复和没用的,我就想通过jexl来提取号码,但开始时每次读excel都抛unrecognize of ole stream 异常。我就怀疑是不是jexl不能读取合并的单元格,尝试了其它excel是可以的,那我就仔细看了移动下载来的excel表格,发现那些excel在有 数据时才存在单元格,没数据地方是空白的。我怀疑这就是问题所在,所以我把移动的excel数据Ctrl + A,再复制到另一个新建的excel文件里,再测试一下读取文件,问题解决了。哎,移动下载来的文件怪怪的,搞到我浪费时间研究这个。
日期问题:获取N天后的日期,主要通过Calendar.add()方法;获取两个日期的间隔天数,主要通过Date的getDate()方法,代码如下:
/**
* 以当前日期为标准,返回n天后的date
*
* @author Chow 2010-7-22
*/
public static Date getDateAfterNDays(int days) {
return getDateAfterNDays(days, new Date());
}
/**
* 以baseDate为标准,返回n天后的date
*
* @author chow 2010-7-22
*/
public static Date getDateAfterNDays(int days, Date baseDate) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(baseDate);
calendar.add(Calendar.DAY_OF_MONTH, days);
return calendar.getTime();
}
/**
* 返回earlyDate 距离 lateDate的天数
*
* @author chow 2010-7-22 下午05:00:47
*/
public static long countDateInterval(Date earlyDate, Date lateDate) {
long intervalDays = 0;
intervalDays = (earlyDate.getTime() - lateDate.getTime())
/ (1000 * 60 * 60 * 24);
return Math.abs(intervalDays);
}