⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pubfunc.java

📁 一套完整的工商12315的源程序jsp部分在12315里,后台JAVA部分在gs12315src里,没有打包数据库.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        return Integer.parseInt(s.substring(14,16));
    }

    //返回日期字符串("yyyy-mm-dd hh:ss:mm")的秒
    public static int getSecond(String s){
        if(s == null || s.length() < 18){
            return 0;
        }
        return Integer.parseInt(s.substring(16,18));
    }

    //返回日期时间字符串对应的日历(格式:"yyyy-mm-dd hh:ss")
    public static Calendar getCal(String s){
        Calendar cal = Calendar.getInstance();
        cal.set(getYear(s),getMonth(s),getDay(s),getHour(s),getMinute(s),getSecond(s));
        return cal;
    }

    //返回日期时间字符串对应的SQL日期(格式:"yyyy-mm-dd hh:ss")
    public static java.sql.Date getSqlDate(String s){
        return java.sql.Date.valueOf(s);
    }

    //返回当天日期对应的SQL日期()
    public static java.sql.Date getSqlDate(){
        return java.sql.Date.valueOf(getNow());
    }

    //取当前日期时间的字符串,格式为"yyyy-mm-dd hh:ss"
    public static String getNow(){
        Calendar now = Calendar.getInstance();
        return getDateStr(now) + " " + getTimeStr(now);
    }

    //取当前日期的字符串,格式为"yyyy-mm-dd"
    public static String getNowDate(){
        Calendar now = Calendar.getInstance();
        return getDateStr(now);
    }

    //取当前时间的字符串,格式为"hh:ss"
    public static String getNowTime(){
        Calendar now = Calendar.getInstance();
        return getTimeStr(now);
    }

    //取当前时间的字符串
    public static String getCurrentTimeMillisStr(){

        return(new Long(System.currentTimeMillis()).toString());
    }

    //取当前时间的字符串
    public static String changTimeMillisToStr(String time){
        long t = 0l;
        try{
            t = Long.parseLong(time);
        } catch(Exception e){
            return "";
        }
        java.util.Date date = new java.util.Date();
        date.setTime(t);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
//        return getDateStrZ(cal) + getTimeStr(cal);
        return getDateStrZ(cal);
    }

    public static String changTimeMillisToStr(long time){
        if(time == 0){
            return "";
        }
        String str = "";
        try{
            str = Long.toString(time);
        } catch(Exception e){
        }
        return changTimeMillisToStr(str);
    }

    //把时间串转变成字符串(格式:yyyy-mm-dd)
    public static String changMillisToDB(long time){
        if(time == 0){
            return "";
        }
        String str = null;
        try{
            java.util.Date date = new java.util.Date();
            date.setTime(time);
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            str = getDateStr(cal);
        } catch(Exception e){
        }
        return str;
    }

    //yinzhijun modify
    //将字符串中的数字0123456789转换成零一二三四五六七八九
    public static String convertToCh(String source){
        String destStr0 = null;
        String destStr1 = null;
        String destStr2 = null;
        String destStr3 = null;
        String destStr4 = null;
        String destStr5 = null;
        String destStr6 = null;
        String destStr7 = null;
        String destStr8 = null;
        String destStr9 = null;

        destStr0 = replace(source,'0',"零");
        destStr1 = replace(destStr0,'1',"一");
        destStr2 = replace(destStr1,'2',"二");
        destStr3 = replace(destStr2,'3',"三");
        destStr4 = replace(destStr3,'4',"四");
        destStr5 = replace(destStr4,'5',"五");
        destStr6 = replace(destStr5,'6',"六");
        destStr7 = replace(destStr6,'7',"七");
        destStr8 = replace(destStr7,'8',"八");
        destStr9 = replace(destStr8,'9',"九");

        return destStr9;

    }

    //将字符串中的数字0123456789转换成零壹贰叁肆伍陆柒捌玖
    public static String convertToFanCh(String source){
        String destStr0 = null;
        String destStr1 = null;
        String destStr2 = null;
        String destStr3 = null;
        String destStr4 = null;
        String destStr5 = null;
        String destStr6 = null;
        String destStr7 = null;
        String destStr8 = null;
        String destStr9 = null;

        destStr0 = replace(source,'0',"零");
        destStr1 = replace(destStr0,'1',"壹");
        destStr2 = replace(destStr1,'2',"贰");
        destStr3 = replace(destStr2,'3',"叁");
        destStr4 = replace(destStr3,'4',"肆");
        destStr5 = replace(destStr4,'5',"伍");
        destStr6 = replace(destStr5,'6',"陆");
        destStr7 = replace(destStr6,'7',"柒");
        destStr8 = replace(destStr7,'8',"捌");
        destStr9 = replace(destStr8,'9',"玖");

        return destStr9;

    }

    //end modify

    /**
     * 字符串替换,将 source 中的 oldString 全部换成 newString
     * @param source 源字符串
     * @param oldString 老的字符串
     * @param newString 新的字符串
     * @return 替换后的字符串
     */
    public static String Replace(String source,String oldString,
                                 String newString){
        try{
            StringBuffer output = new StringBuffer();

            int lengthOfSource = source.length(); // 源字符串长度
            int lengthOfOld = oldString.length(); // 老字符串长度

            int posStart = 0; // 开始搜索位置
            int pos; // 搜索到老字符串的位置

            while((pos = source.indexOf(oldString,posStart)) >= 0){
                output.append(source.substring(posStart,pos));

                output.append(newString);
                posStart = pos + lengthOfOld;
            }

            if(posStart < lengthOfSource){
                output.append(source.substring(posStart));
            }
            return output.toString();
        } catch(Exception e){
            return source;
        }
    }

    /**
     * 将字符串格式化成 HTML 代码输出
     * @param str 要格式化的字符串
     * @return 格式化后的字符串
     */
    public static String toHtml(String str){

        String html = str;
        html = Replace(html,"&","&amp;");
        html = Replace(html,"<","&lt;");
        html = Replace(html,">","&gt;");
        html = Replace(html,"\"","&quot;");
        html = Replace(html,"\r\n","\n");
        html = Replace(html,"\n","<br>\n");
        html = Replace(html,"\t","    ");
        html = Replace(html,"  "," &nbsp;");

        return html;
    }

    /**
     * 将字符串格式化成 HTML 代码输出
     * 用于显示在form中
     * @param str 要格式化的字符串
     * @return 格式化后的字符串
     */
    public static String toHtml(String str,int i){

        String html = str;
        //html = Replace(html, "&", "&amp;");
        //html = Replace(html, "<", "&lt;");
        //html = Replace(html, ">", "&gt;");
        html = Replace(html,"\"","&quot;");
        html = Replace(html,"\r\n","\n");
        //html = Replace(html, "\n", "<br>\n");
        //html = Replace(html, "\t", "    ");
        //html = Replace(html, "  ", " &nbsp;");

        return html;
    }

    /**
     * 把单引号替换为双单引号,用于sql
     * @param sqlstr 要格式化的字符串
     * @return 格式化后的字符串
     */
    public static String toSql(String sqlstr){

        if(sqlstr == null || sqlstr.length() == 0){
            return "";
        } else{
            sqlstr = sqlstr.trim();
            try{
                sqlstr = new String(sqlstr.getBytes("ISO-8859-1"),"GBK");
            } catch(Exception e){
            }
//            sqlstr = encodeGB(sqlstr);
            return Replace(sqlstr,"'","''");
        }
    }

    /**
     * 把单引号替换为双单引号,用于sql
     * @param sqlstr 要格式化的字符串
     * @return 格式化后的字符串
     */
    public static String toSql(String sqlstr,int flag){
        if(sqlstr == null || sqlstr.length() == 0){
            return "";
        } else{
            if(flag == 1){
                try{
                    sqlstr = new String(sqlstr.getBytes("ISO-8859-1"),"GBK");
                } catch(Exception e){
                }
            }
//            sqlstr = encodeGB(sqlstr);
            return Replace(sqlstr,"'","''");
        }
    }

    /**
     * 显示从数据库中提出的数据在html显示做必要的处理
     * @param str 要格式化的字符串
     * @return 格式化后的字符串
     */
    public static String toShow(String str){

        if(str == null || str.length() == 0){
            return "&nbsp;";
        } else{
//            str = decodeGB(str);
            str = str.trim();
            str = toHtml(str);
            return str;
        }
    }

    public static String toShow(String str,int theSwitch){
        if(str == null || str.length() == 0){
            return "";
        } else{
            if(theSwitch == 1){
                //               str = decodeGB(str);
            }
            str = toHtml(str);
            return str.trim();
        }
    }

    /**
     * 显示从数据库中提出的数据在html显示做必要的处理
     * 用于显示在form中
     * @param str 要格式化的字符串
     * @return 格式化后的字符串
     */
    public static String toShowForm(String str){
        if(str == null || str.length() == 0){
            return "";
        } else{
            //           str = decodeGB(str);
            str = str.trim();
            return toHtml(str,0);
        }
    }

    public static String toShowForm(String str,int theSwitch){
        if(str == null || str.length() == 0){
            return "";
        } else{
            if(theSwitch == 1){
//                str = decodeGB(str);
            }
            str = str.trim();
            return toHtml(str,0);
        }
    }

    public static String rTrim(String source){
        if(source == null || source.length() == 0){
            return "";
        }
        StringBuffer sourceBuf = new StringBuffer(source);
        while(sourceBuf.charAt(sourceBuf.length() - 1) == ' '){
            sourceBuf.deleteCharAt(sourceBuf.length() - 1);
        }
        return sourceBuf.toString();
    }

    public static String toShowRTrim(String str){
        if(str == null || str.length() == 0){
            return "&nbsp;";
        } else{
//            str = decodeGB(str);
            str = rTrim(str);
            str = toHtml(str);
            return str;
        }
    }

    /** ljc Add
     * 分割串
     * eg. abc\xyz\efg1234 或 \abc\xyz\efg1234\ 或 ##abc##xyz##efg1234
     * 说明:若源串不含分割串,则返回源串
     * 若分割串为null或空串,则返回源串
     *@param srcStr 输入串
     *@param splitStr 分割串
     */
    public static String[] splitStr(String srcStr,String splitStr){
        String str = srcStr; //backup
        ArrayList al = new ArrayList();

        if(str == null){
            al = null; //exception
        } else if(splitStr == null || splitStr.equals("")){
            al.add(str);
        } else{
            int ssLen = splitStr.length();
            if(str.substring(0,ssLen).equals(splitStr)){
                str = str.substring(ssLen,str.length()); //去除首位分割串
            }
            if(!str.substring(str.length() - ssLen,str.length()).equals(splitStr)){
                str += splitStr; //加上末位分割串
            }
            int fromPos = 0;
            int newPos;
            while((newPos = str.indexOf(splitStr,fromPos)) != -1){ //found
                String tmpStr = str.substring(fromPos,newPos);
                al.add(tmpStr);
                fromPos = newPos + ssLen;
            }
        }

        if(al == null || al.size() == 0){
            return null;
        } else{
            String[] strArray = new String[al.size()];
            for(int i = 0;i < al.size();i++){
                strArray[i] = (String) al.get(i);
            }
            return strArray;
        }
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -