Hello,大家好!我是程序员阿飞!好久没有更新文章了,很是惭愧!所以,从今天开始以后每周末我会定时更新一篇文章,主要是一周内的学习总结,以便以后的复习和回顾。好了,现在就开始吧!
一、根据地址获得数据的字节流
/**
* 根据地址获得数据的字节流
* @param strUrl 网络连接地址
* @return
*/
public static byte[] getImageFromNetByUrl(String strUrl){
try {
URL url = new URL(strUrl);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
InputStream inStream = conn.getInputStream();//通过输入流获取图片数据
byte[] btImg = readInputStream(inStream);//得到图片的二进制数据
return btImg;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
二、从输入流中获取数据
/**
* 从输入流中获取数据
* @param inStream 输入流
* @return
* @throws Exception
*/
public static byte[] readInputStream(InputStream inStream) throws Exception{
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while( (len=inStream.read(buffer)) != -1 ){
outStream.write(buffer, 0, len);
}
inStream.close();
return outStream.toByteArray();
}
}
三、javascript计算两个时间差
var d1 = new Date('2016/03/28 10:17:22');
var d2 = new Date('2016/03/28 11:17:22');
console.log(parseInt(d2 - d1));//两个时间相差的毫秒数
console.log(parseInt(d2 - d1) / 1000);//两个时间相差的秒数
console.log(parseInt(d2 - d1) / 1000 / 60);//两个时间相差的分钟数
console.log(parseInt(d2 - d1) / 1000 / 60);//两个时间相差的小时数
四、jquery定时刷新
/**
* 办理时间倒计时
*/
function SetRemainTime(rpTime,spotId,fourplatformCode) {
var currentTime = new Date();
var sysSecond = parseInt(rpTime - currentTime) / 1000;//这里获取倒计时的起始时间
if (sysSecond > 0) {
sysSecond = sysSecond - 1;
var second = Math.floor(sysSecond % 60); //计算秒
var minute = Math.floor((sysSecond / 60) % 60); //计算分
var hour = Math.floor((sysSecond / 3600) % 24); //计算小时
var day = Math.floor((sysSecond / 3600) / 24); //计算天
if(day==0){
$("#"+spotId+"").html("来自:"+fourplatformCode+" 剩余:"+day + "天" + hour + "小时" + minute + "分" + second + "秒逾期");
$("#"+spotId+"").css({"background":"url(../spotnew/img/by.png) no-repeat","width":"25%","background-size":"100% 35px"});
}else{
$("#"+spotId+"").html("来自:"+fourplatformCode+" 剩余:"+day + "天" + hour + "小时" + minute + "分" + second + "秒");
$("#"+spotId+"").css({"width":"25%","background-size":"100% 35px"});
}
}else{
var overSecond = parseInt(currentTime - rpTime) / 1000;
overSecond = overSecond - 1;
var second = Math.floor(overSecond % 60); //计算秒
var minute = Math.floor((overSecond / 60) % 60); //计算分
var hour = Math.floor((overSecond / 3600) % 24); //计算小时
var day = Math.floor((overSecond / 3600) / 24); //计算天
$("#"+spotId+"").html("来自:"+fourplatformCode+" 已逾期:"+day + "天" + hour + "小时" + minute + "分" + second + "秒");
$("#"+spotId+"").css({"background":"url(../spotnew/img/br.png) no-repeat","width":"25%","background-size":"100% 35px"});
}
}
五、jquery日期加指定天数
/**
* 日期加指定天数
*/
function addDay(dayNumber, date) {
date = date ? date : new Date();
var ms = dayNumber * (1000 * 60 * 60 * 24);
var newDate = new Date(date.getTime() + ms);
return newDate;
}
六、使用ajaxSubmit进行form表单提交
$("#queryForm").ajaxSubmit(function(data){
var content2=data.replace(/<\/?.+?>/g,"");
var content3=content2.replace(/ /g,"");//将返回的data数据进行解析去除html标签
var jsObject = JSON.parse(content3);//将json字符串转换成json对象
if(jsObject.resCode==0){
$.messager.alert("提示", jsObject.resMsg);
setTimeout(function () {
delayExecute();
},2000);
}else{
$.messager.alert("提示", jsObject.resMsg);
}
});
七、关闭子窗口,返回父窗口并刷新页面
function delayExecute() {
window.self.close();
window.opener.location.reload();
}
【参考网址】
https://blog.csdn.net/haocaicai/article/details/85181280
https://www.cnblogs.com/smartsmile/p/6234028.html
https://www.cnblogs.com/kissdodog/p/5419913.html
https://www.cnblogs.com/wzhanke/p/4817729.html