- 浏览: 15528 次
- 性别:
- 来自: 广州
文章分类
收藏列表
标题 | 标签 | 来源 | |
tomcat jndi连接mysql | tomcat jndi连接mysql | ||
<WatchedResource>WEB-INF/web.xml</WatchedResource> <!-- 加入这行 --> <Resource name="<span style="color: #ff0000;">jdbc/wb</span>" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test" username="root" password="root" maxActive="20" maxIdle="10" maxWait="-1"/> |
|||
Tomcat中采用HTTPS访问 | Tomcat中采用HTTPS访问 | ||
Server version: Apache Tomcat/6.0.35 Server built: Nov 28 2011 11:20:06 Server number: 6.0.35.0 OS Name: Windows XP OS Version: 5.1 Architecture: x86 JVM Version: 1.6.0_21-b06 JVM Vendor: Sun Microsystems Inc. |
|||
xx | xxx | java之7天 继承,final,接口,抽象类 | |
/** 将学生和工人的共性描述提取出来,单独进行描述, 只要让学生和工人与单独描述的这个类有关系,就可以了. 继承: 1.提高代码的复用性 2.让类与类之间产生了关系, 有了这个关系类,才有了多态的特性.. */ class Persion{ String name; int age; } class Student extends Person{ //String name; // int age; void study( System.out.println("goog study"); ) class Worker extends Person{ // String name; // int age; void work(){ System.out.println("good work"); } } } /* 注意:千万不要为了获取其他类的功能,简化代码而继承, 必须是类与类之间有所属关系才可以继承,所属关系 is a. */ class A{ void demo1(){} void demo2(){} } class B extends A { //void demo1(){} 发现 B也有 demo2() 这个功能 说明不能乱继承,我们可以将 demo抽成出一个 父类 .但是 B 不能继承 A void demo3()} } /* Java语言中,Java只支持单继承,不支持多继承. 因为多继承 容易带来安全隐患. 当功能内容不同时,子类对象不确定要运行那个 但是java保留了这种机制,并用另一种体现形式来完成,多实现 */ class A{ void show(){ System.out.println("A"); } } class B{ void show(){ System.out.println("B"); } } class C extends A,B{ public statiac void main(String [] args){ C c=new C(); c.show(); //如果出现多继承 此时就不知道是打印 A 还是 B 所以java不支持多继承. } } /* 要先使用体系,先查阅体系父类的描述,因为父类中定义了该体系中共性功能. 通过了解共性功能,就可以知道该体系的基本功能 在具体调用时,要创建最子类的对象,为什么呢? 1:一是因为有可能父类不能创建独享 2.创建子类对象可以使更多的个功能,包括基本的也包括特有的 */ |
|||
java多线程下载核心代码 | 多线程 | Java多线程下载核心代码 | |
package com.java.net; import java.io.IOException; import java.io.InputStream; import java.io.RandomAccessFile; import java.net.URL; import java.net.URLConnection; class Download extends Thread{ //定义字节数组(取水的竹筒)的长度 private final int BUFF_LEN = 32; //定义下载的起始点 private long start; //定义下载的结束点 private long end; //下载资源对应的输入流 private InputStream is; //将下载的字节输出到raf中 private RandomAccessFile raf; public Download() { } public Download(long start, long end, InputStream is, RandomAccessFile raf) { System.out.println(start + "---------->" + end); this.start = start; this.end = end; this.is = is; this.raf = raf; } @Override public void run() { try { is.skip(start); raf.seek(start); //定义读取输入流内容的缓存数组(竹筒) byte[] buff = new byte[BUFF_LEN]; //本线程负责下载资源的大小 long contentLen = end - start; //定义最多需要读取几次就可以完成本线程下载 long times = contentLen / BUFF_LEN + 4; //实际读取的字节 int hasRead = 0; for(int i=0; i<times; i++){ hasRead = is.read(buff); if(hasRead < 0){ break; } raf.write(buff, 0, hasRead); } } catch (IOException e) { e.printStackTrace(); } finally { try { if(is != null) is.close(); if(raf != null) raf.close(); } catch (Exception e2) { e2.printStackTrace(); } } } } public class MutilDown { public static void main(String[] args) { final int DOWN_THREAD_NUM = 4; final String OUT_FILE_NAME = "e:/down.jpg"; InputStream[] isArr = new InputStream[DOWN_THREAD_NUM]; RandomAccessFile[] outArr = new RandomAccessFile[DOWN_THREAD_NUM]; try { URL url = new URL("http://www.blueidea.com/articleimg/2006/08/3912/images/plant4.jpg"); //依次URL打开一个输入流 isArr[0] = url.openStream(); long fileLen = getFileLength(url); System.out.println("网络资源的大小:" + fileLen); outArr[0] = new RandomAccessFile(OUT_FILE_NAME, "rw"); for(int i=0; i<fileLen; i++){ outArr[0].write(0); } long numPerThred = fileLen / DOWN_THREAD_NUM; //整个下载资源整除后剩下的余数 long left = fileLen % DOWN_THREAD_NUM; for(int i=0; i<DOWN_THREAD_NUM; i++){ //为每条线程打开一条输入流,一个RandomAccessFile对象 //让每个线程分别下载文件的不同部分 if(i != 0){ //以URL打开多个输入流 isArr[i] = url.openStream(); outArr[i] = new RandomAccessFile(OUT_FILE_NAME, "rw"); } //分别启动多个线程来下载网络资源 if( i == DOWN_THREAD_NUM - 1){ //最后一个线程下载指定numPerThred + left个字节 new Download(i * numPerThred, (i + 1) * numPerThred + left, isArr[i], outArr[i]).start(); }else{ //每个线程负责下载一定的numPerThred个字节 new Download(i * numPerThred, (i + 1) * numPerThred, isArr[i], outArr[i]).start(); } } } catch (Exception e) { e.printStackTrace(); } } //定义获取指定网络资源的方法 public static long getFileLength(URL url) throws IOException{ long length = 0; //打开URL对应的URLConnection URLConnection con = url.openConnection(); long size = con.getContentLength(); length = size; return length; } } |
|||
通过修改注册表,在右键菜单上添加 "Compress JS using YUI Compressor“ 菜单项 | 压缩 | ||
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\AllFilesystemObjects\shell] [HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Compress JS using YUI Compressor] [HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Compress JS using YUI Compressor\command] @="java -jar F:\\wl470\\webtv\\模拟器\\tomcat\\webapps\\EPG\\GR\\yuicompressor-2.4.2.jar --charset UTF-8 \"%1\" -o \"%1\"" |
|||
弹出的层绝对屏幕居中 | ie7 | 如何让JS弹出的层绝对屏幕居中 | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style type="text/css"> /*弹出层的STYLE*/ html,body {height:100%; margin:0px; font-size:12px;} .mydiv { background-color: #ff6; border: 1px solid #f90; text-align: center; line-height: 40px; font-size: 12px; font-weight: bold; z-index:99; width: 300px; height: 120px; left:50%;/*FF IE7*/ top: 50%;/*FF IE7*/ margin-left:-150px!important;/*FF IE7 该值为本身宽的一半 */ margin-top:-60px!important;/*FF IE7 该值为本身高的一半*/ margin-top:0px; position:fixed!important;/*FF IE7*/ position:absolute;/*IE6*/ _top: expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop + (document.documentElement.clientHeight-this.offsetHeight)/2 :/*IE6*/ document.body.scrollTop + (document.body.clientHeight - this.clientHeight)/2);/*IE5 IE5.5*/ } .bg { background-color: #ccc; width: 100%; height: 100%; left:0; top:0;/*FF IE7*/ filter:alpha(opacity=50);/*IE*/ opacity:0.5;/*FF*/ z-index:1; position:fixed!important;/*FF IE7*/ position:absolute;/*IE6*/ _top: expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop + (document.documentElement.clientHeight-this.offsetHeight)/2 :/*IE6*/ document.body.scrollTop + (document.body.clientHeight - this.clientHeight)/2);/*IE5 IE5.5*/ } /*The END*/ </style> <script type="text/javascript"> function showDiv(){ document.getElementById('popDiv').style.display='block'; document.getElementById('bg').style.display='block'; } function closeDiv(){ document.getElementById('popDiv').style.display='none'; document.getElementById('bg').style.display='none'; } </script> </head> <body> <div id="popDiv" class="mydiv" style="display:none;">恭喜你!<br/>你的成绩为:60分<br/> <a href="javascript:closeDiv()">关闭窗口</a></div> <div id="bg" class="bg" style="display:none;"></div> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> <div style="padding-top: 20px;"> <input type="Submit" name="" value="显示层" onclick="javascript:showDiv()" /> </div> </body> </html> |
|||
发一个自己写的秒杀参与程序,纯分享,无他用。 | 发一个自己写的秒杀参与程序,纯分享,无他用。 | ||
Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443); Protocol.registerProtocol("https", easyhttps); HttpClient httpClient = new HttpClient(); //字符编码 httpClient.getParams().setContentCharset("gbk"); HostConfiguration hc = new HostConfiguration(); hc.setHost("www.uqbook.cn", 80, easyhttps); String configId = "200011111111444444"; String agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"; String refer = "https://www.uqbook.cn/sec_initListInfo.action"; String contentType = "application/x-www-form-urlencoded; charset=UTF-8"; //Cookie String cookie = "JSESSIONID1=pkfXNQDY0DTKRpch4ngp62hD1LNmcp5Jpn8G2R2LQVylxHcH1hpr!-595124091"; String inputsubje = "";//答案一 String inputArith = "68";//答案二 int i = 1; boolean isFirstIn = true; while (true) { if(isFirstIn){ //进入页面 GetMethod inMethod = new GetMethod("https://www.uqbook.cn/initInfo.action"); // 设置参数 inMethod.setRequestHeader("User-Agent", agent); inMethod.setRequestHeader("Referer", refer); inMethod.setRequestHeader("Cookie", cookie); try { int codeCode = httpClient.executeMethod(hc, inMethod); InputStream inResp = inMethod.getResponseBodyAsStream(); //循环读取每一行 BufferedReader reader = new BufferedReader(new InputStreamReader(inResp)); String line = null; String sysCurrentTime = ""; String secondTt = ""; while ((line = reader.readLine())!=null){ //对读取的数据进行编码转换 line = new String(line.getBytes(),"gb2312"); line = line.trim(); if(line.startsWith("var sysCurrentTime")){ sysCurrentTime = line.substring(line.indexOf("\"")+1, line.lastIndexOf("\"")); }else if(line.startsWith("var secondTt")){ secondTt = line.substring(line.indexOf("'")+1, line.lastIndexOf("'")); } //logger.info(line); if(sysCurrentTime!="" && secondTt!=""){ break; } } reader.close(); logger.info("服务器时间:sysCurrentTime="+sysCurrentTime); logger.info("本机时间:"+DateUtil.getCurrentDateStr(DateUtil.C_TIME_PATTON_DEFAULT)); logger.info("还没到点...等待"+secondTt+"秒..."); Thread.sleep(Integer.parseInt(secondTt)); } catch (Exception e) { e.printStackTrace(); logger.error("进入页面得到倒计时间异常:" + e); continue;//继续来一次 } } isFirstIn = false; // 1、取问题及答案 PostMethod subInfoMethod = new PostMethod("https://www.uqbook.cn/getSubjectInfo.action"); // 设置参数 subInfoMethod.setRequestHeader("User-Agent", agent); subInfoMethod.setRequestHeader("Referer", refer); subInfoMethod.setRequestHeader("Cookie", cookie); subInfoMethod.addParameter("timeStamp", ""+System.currentTimeMillis()); subInfoMethod.addParameter("configId", configId); try { int subInfoCode = httpClient.executeMethod(hc, subInfoMethod); String subInfoResp = subInfoMethod.getResponseBodyAsString(); if (subInfoResp == null || "".equals(subInfoResp)) { logger.info("还没有发布安全问题及答案,本次退出,继续执行下一次!"); continue; } logger.info("安全问题及答案解码:" + EscapeUnescape.unescape(subInfoResp)); // 解析 JSON JSONArray array = JSON.parseArray(subInfoResp); JSONObject object = (JSONObject) array.get(0); String content = object.getString("subjectContent"); inputArith = object.getString("arithmeticAnswer"); content = EscapeUnescape.unescape(content).replace("@", " "); Parser parser = new Parser(); parser.setInputHTML(content); parser.elements(); for (NodeIterator it = parser.elements(); it.hasMoreNodes();) { Node node = it.nextNode(); if (node instanceof TagNode) { TagNode tag = (TagNode) node; if ("ttwrsnspysk".equalsIgnoreCase(tag .getAttribute("id"))) { inputsubje = tag.toPlainTextString().trim(); } } ; } } catch (Exception e) { e.printStackTrace(); } inputArith = "27"; if (inputsubje == null || "".equals(inputsubje) || inputArith == null || "".equals(inputArith)) { logger.info("获安全问题及答案时可能发生异常了,本次退出,继续执行下一次!"); continue; } //2、判断 是否参加过 PostMethod judgementSecSalMethod = new PostMethod("https://www.uqbook.cn/judgement.action"); // 设置参数 judgementSecSalMethod.setRequestHeader("User-Agent", agent); judgementSecSalMethod.setRequestHeader("Referer", refer); judgementSecSalMethod.setRequestHeader("Cookie", cookie); judgementSecSalMethod.addParameter("timeStamp", ""+System.currentTimeMillis()); judgementSecSalMethod.addParameter("configId", configId); try { int judgementSecSalCode = httpClient.executeMethod(hc, judgementSecSalMethod); String judgementSecSalResp = judgementSecSalMethod.getResponseBodyAsString(); } catch (Exception e) { e.printStackTrace(); } //3、验证问题和答案是否正确 PostMethod checkMethod = new PostMethod("https://www.uqbook.cn/judgementAnswer.action"); // 设置参数 checkMethod.setRequestHeader("User-Agent", agent); checkMethod.setRequestHeader("Content-Type", contentType); checkMethod.setRequestHeader("Referer", refer); checkMethod.setRequestHeader("Cookie", cookie); checkMethod.addParameter("timeStamp", ""+System.currentTimeMillis()); String tempInputsubje = inputsubje; try { tempInputsubje = URLEncoder.encode(inputsubje, "utf-8"); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } checkMethod.addParameter("inputsubje", tempInputsubje); checkMethod.addParameter("inputArith", inputArith); try { int checkCode = httpClient.executeMethod(hc, checkMethod); String checkResp = checkMethod.getResponseBodyAsString(); } catch (Exception e) { e.printStackTrace(); } // 3、提交抢购! PostMethod submitMethod = new PostMethod("https://www.uqbook.cn/submit.action"); // 设置参数 submitMethod.setRequestHeader("User-Agent", agent); submitMethod.setRequestHeader("Referer", refer); submitMethod.setRequestHeader("Cookie", cookie); submitMethod.addParameter("timeStamp", ""+System.currentTimeMillis()); submitMethod.addParameter("inputsubje", EscapeUnescape.escape(inputsubje));// 编一下码 submitMethod.addParameter("inputArith", inputArith); submitMethod.addParameter("configId", configId); try { int submitCode = httpClient.executeMethod(hc, submitMethod); String submitResp = submitMethod.getResponseBodyAsString(); JSONArray array = JSON.parseArray(submitResp); JSONObject object = (JSONObject) array.get(0); String sign = object.getString("sign"); if ("yes".equals(sign)) { logger.info("抢购登记成功, 退出程序!"); break; } logger.info("抢购登记失败,继续..."); } catch (Exception e) { logger.error("提交抢购异常:" + e); } subInfoMethod.releaseConnection(); submitMethod.releaseConnection(); break; } |
|||
JavaScript Date Format | js日期时间函 | JavaScript Date Format | |
var now = new Date(); now.format("m/dd/yy"); // Returns, e.g., 6/09/07 // Can also be used as a standalone function dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT"); // Saturday, June 9th, 2007, 5:46:21 PM // You can use one of several named masks now.format("isoDateTime"); // 2007-06-09T17:46:21 // ...Or add your own dateFormat.masks.hammerTime = 'HH:MM! "Can\'t touch this!"'; now.format("hammerTime"); // 17:46! Can't touch this! // When using the standalone dateFormat function, // you can also provide the date as a string dateFormat("Jun 9 2007", "fullDate"); // Saturday, June 9, 2007 // Note that if you don't include the mask argument, // dateFormat.masks.default is used now.format(); // Sat Jun 09 2007 17:46:21 // And if you don't include the date argument, // the current date and time is used dateFormat(); // Sat Jun 09 2007 17:46:22 // You can also skip the date argument (as long as your mask doesn't // contain any numbers), in which case the current date/time is used dateFormat("longTime"); // 5:46:22 PM EST // And finally, you can convert local time to UTC time. Either pass in // true as an additional argument (no argument skipping allowed in this case): dateFormat(now, "longTime", true); now.format("longTime", true); // Both lines return, e.g., 10:46:21 PM UTC // ...Or add the prefix "UTC:" to your mask. now.format("UTC:h:MM:ss TT Z"); // 10:46:21 PM UTC |
|||
js日期时间函数(经典+完善+实用) | js日期时间函 | js日期时间函数(经典+完善+实用) | |
//--------------------------------------------------- // 判断闰年 //--------------------------------------------------- Date.prototype.isLeapYear = function() { return (0==this.getYear()%4&&((this.getYear()%100!=0)||(this.getYear()%400==0))); } //--------------------------------------------------- // 日期格式化 // 格式 YYYY/yyyy/YY/yy 表示年份 // MM/M 月份 // W/w 星期 // dd/DD/d/D 日期 // hh/HH/h/H 时间 // mm/m 分钟 // ss/SS/s/S 秒 //--------------------------------------------------- Date.prototype.Format = function(formatStr) { var str = formatStr; var Week = ['日','一','二','三','四','五','六']; str=str.replace(/yyyy|YYYY/,this.getFullYear()); str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100)); str=str.replace(/MM/,this.getMonth()>9?this.getMonth().toString():'0' + this.getMonth()); str=str.replace(/M/g,this.getMonth()); str=str.replace(/w|W/g,Week[this.getDay()]); str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate()); str=str.replace(/d|D/g,this.getDate()); str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours()); str=str.replace(/h|H/g,this.getHours()); str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes()); str=str.replace(/m/g,this.getMinutes()); str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds()); str=str.replace(/s|S/g,this.getSeconds()); return str; } //+--------------------------------------------------- //| 求两个时间的天数差 日期格式为 YYYY-MM-dd //+--------------------------------------------------- function daysBetween(DateOne,DateTwo) { var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ('-')); var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ('-')+1); var OneYear = DateOne.substring(0,DateOne.indexOf ('-')); var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ('-')); var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ('-')+1); var TwoYear = DateTwo.substring(0,DateTwo.indexOf ('-')); var cha=((Date.parse(OneMonth+'/'+OneDay+'/'+OneYear)- Date.parse(TwoMonth+'/'+TwoDay+'/'+TwoYear))/86400000); return Math.abs(cha); } //+--------------------------------------------------- //| 日期计算 //+--------------------------------------------------- Date.prototype.DateAdd = function(strInterval, Number) { var dtTmp = this; switch (strInterval) { case 's' :return new Date(Date.parse(dtTmp) + (1000 * Number)); case 'n' :return new Date(Date.parse(dtTmp) + (60000 * Number)); case 'h' :return new Date(Date.parse(dtTmp) + (3600000 * Number)); case 'd' :return new Date(Date.parse(dtTmp) + (86400000 * Number)); case 'w' :return new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number)); case 'q' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number*3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); case 'm' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); case 'y' :return new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); } } //+--------------------------------------------------- //| 比较日期差 dtEnd 格式为日期型或者 有效日期格式字符串 //+--------------------------------------------------- Date.prototype.DateDiff = function(strInterval, dtEnd) { var dtStart = this; if (typeof dtEnd == 'string' )//如果是字符串转换为日期型 { dtEnd = StringToDate(dtEnd); } switch (strInterval) { case 's' :return parseInt((dtEnd - dtStart) / 1000); case 'n' :return parseInt((dtEnd - dtStart) / 60000); case 'h' :return parseInt((dtEnd - dtStart) / 3600000); case 'd' :return parseInt((dtEnd - dtStart) / 86400000); case 'w' :return parseInt((dtEnd - dtStart) / (86400000 * 7)); case 'm' :return (dtEnd.getMonth()+1)+((dtEnd.getFullYear()-dtStart.getFullYear())*12) - (dtStart.getMonth()+1); case 'y' :return dtEnd.getFullYear() - dtStart.getFullYear(); } } //+--------------------------------------------------- //| 日期输出字符串,重载了系统的toString方法 //+--------------------------------------------------- Date.prototype.toString = function(showWeek) { var myDate= this; var str = myDate.toLocaleDateString(); if (showWeek) { var Week = ['日','一','二','三','四','五','六']; str += ' 星期' + Week[myDate.getDay()]; } return str; } //+--------------------------------------------------- //| 日期合法性验证 //| 格式为:YYYY-MM-DD或YYYY/MM/DD //+--------------------------------------------------- function IsValidDate(DateStr) { var sDate=DateStr.replace(/(^\s+|\s+$)/g,''); //去两边空格; if(sDate=='') return true; //如果格式满足YYYY-(/)MM-(/)DD或YYYY-(/)M-(/)DD或YYYY-(/)M-(/)D或YYYY-(/)MM-(/)D就替换为'' //数据库中,合法日期可以是:YYYY-MM/DD(2003-3/21),数据库会自动转换为YYYY-MM-DD格式 var s = sDate.replace(/[\d]{ 4,4 }[\-/]{ 1 }[\d]{ 1,2 }[\-/]{ 1 }[\d]{ 1,2 }/g,''); if (s=='') //说明格式满足YYYY-MM-DD或YYYY-M-DD或YYYY-M-D或YYYY-MM-D { var t=new Date(sDate.replace(/\-/g,'/')); var ar = sDate.split(/[-/:]/); if(ar[0] != t.getYear() || ar[1] != t.getMonth()+1 || ar[2] != t.getDate()) { //alert('错误的日期格式!格式为:YYYY-MM-DD或YYYY/MM/DD。注意闰年。'); return false; } } else { //alert('错误的日期格式!格式为:YYYY-MM-DD或YYYY/MM/DD。注意闰年。'); return false; } return true; } //+--------------------------------------------------- //| 日期时间检查 //| 格式为:YYYY-MM-DD HH:MM:SS //+--------------------------------------------------- function CheckDateTime(str) { var reg = /^(\d+)-(\d{ 1,2 })-(\d{ 1,2 }) (\d{ 1,2 }):(\d{ 1,2 }):(\d{ 1,2 })$/; var r = str.match(reg); if(r==null)return false; r[2]=r[2]-1; var d= new Date(r[1],r[2],r[3],r[4],r[5],r[6]); if(d.getFullYear()!=r[1])return false; if(d.getMonth()!=r[2])return false; if(d.getDate()!=r[3])return false; if(d.getHours()!=r[4])return false; if(d.getMinutes()!=r[5])return false; if(d.getSeconds()!=r[6])return false; return true; } //+--------------------------------------------------- //| 把日期分割成数组 //+--------------------------------------------------- Date.prototype.toArray = function() { var myDate = this; var myArray = Array(); myArray[0] = myDate.getFullYear(); myArray[1] = myDate.getMonth(); myArray[2] = myDate.getDate(); myArray[3] = myDate.getHours(); myArray[4] = myDate.getMinutes(); myArray[5] = myDate.getSeconds(); return myArray; } //+--------------------------------------------------- //| 取得日期数据信息 //| 参数 interval 表示数据类型 //| y 年 m月 d日 w星期 ww周 h时 n分 s秒 //+--------------------------------------------------- Date.prototype.DatePart = function(interval) { var myDate = this; var partStr=''; var Week = ['日','一','二','三','四','五','六']; switch (interval) { case 'y' :partStr = myDate.getFullYear();break; case 'm' :partStr = myDate.getMonth()+1;break; case 'd' :partStr = myDate.getDate();break; case 'w' :partStr = Week[myDate.getDay()];break; case 'ww' :partStr = myDate.WeekNumOfYear();break; case 'h' :partStr = myDate.getHours();break; case 'n' :partStr = myDate.getMinutes();break; case 's' :partStr = myDate.getSeconds();break; } return partStr; } //+--------------------------------------------------- //| 取得当前日期所在月的最大天数 //+--------------------------------------------------- Date.prototype.MaxDayOfDate = function() { var myDate = this; var ary = myDate.toArray(); var date1 = (new Date(ary[0],ary[1]+1,1)); var date2 = date1.dateAdd(1,'m',1); var result = dateDiff(date1.Format('yyyy-MM-dd'),date2.Format('yyyy-MM-dd')); return result; } //+--------------------------------------------------- //| 取得当前日期所在周是一年中的第几周 //+--------------------------------------------------- Date.prototype.WeekNumOfYear = function() { var myDate = this; var ary = myDate.toArray(); var year = ary[0]; var month = ary[1]+1; var day = ary[2]; document.write('< script language=VBScript\> \n'); document.write('myDate = DateValue(''+month+'-'+day+'-'+year+'') \n'); document.write('result = DatePart('ww', myDate) \n'); document.write(' \n'); return result; } //+--------------------------------------------------- //| 字符串转成日期类型 //| 格式 MM/dd/YYYY MM-dd-YYYY YYYY/MM/dd YYYY-MM-dd //+--------------------------------------------------- function StringToDate(DateStr) { var converted = Date.parse(DateStr); var myDate = new Date(converted); if (isNaN(myDate)) { //var delimCahar = DateStr.indexOf('/')!=-1?'/':'-'; var arys= DateStr.split('-'); myDate = new Date(arys[0],--arys[1],arys[2]); } return myDate; } |