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

📄 tools.java

📁 系统工具类操作模块,主要用于站内搜索,并定义显示格式
💻 JAVA
字号:
	 /**
	 * 功能描述:系统工具类操作模块
	 * 编 写 人:wjw
	 * 编写日期:2005-7-5
     * 修改日期:2005-7-17
	 */
package tl;
import java.text.SimpleDateFormat;
import java.text.*;
import java.util.Date;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 * @author Administrator
 *
 * TODO 要更改此生成的类型注释的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
public class Tools 
{
public String dbIConvertG(String str)		//查询
{
	if(str==null)
	{
 			str  ="" ;
 		}
 		else
 		{
     		try {
    			str = new String(str.getBytes("iso-8859-1"),"gb2312") ;
    	     	    }
    	catch (Exception ex)
     		{
     		 	System.out.println("参数输入错误,请返回重新输入!!");
     		}
 		}
 		return str ;
	
}

public String dbgGConvertI(String str)		//插入
{
	if(str==null)
	{
 			str  ="" ;
 		}
 		else
 		{
     		try {
    			str = new String(str.getBytes("gb2312"),"iso-8859-1") ;
    	     	    }
  catch (Exception ex)
     		{
     		 	System.out.println("参数输入错误,请返回重新输入!!");
     		}
 		}
 		return str ;
	
}

 	 /**
	 * 功能描述:得到999999之间的随机数据
	 * 输    入: int iCount(总列数),int iNowCol(当前列数),int iCols(总行数)
	 * 输    出:随机数
	 * 编 写 人:wjw
	 * 编写日期:2005-7-5
     * 修改日期:
	 */
public int getGrsn()
	{
     Date dh=new Date();
     int d=dh.getDay();
     int h=dh.getHours();
     int m=dh.getMinutes();
     int sSj=d+h+m;
     int sGrsn=(int)(Math.random()*999999+1);
     return sGrsn+sSj;
	}



	 /**
	 * 功能描述:检查当前行数,不足补空行模块
	 * 输    入: int iCount(总列数),int iNowCol(当前列数),int iCols(总行数)
	 * 输    出:sResult(返回提交后信息)
	 * 编 写 人:wjw
	 * 编写日期:2005-7-5
     * 修改日期:
	 */
 public String tlsCheckLine(int iCount,int iNowCol,int iCols)
  {
	 String sResult="";
	   for(int ib=1;ib<=iCount-iNowCol;ib++)
        {
			sResult+="<tr bgcolor=#FFFFFF class=NewButton  height=25>";
			for(int b=1;b<=iCols;b++)
		    {
  				sResult +=" <td height=23></td>";
		    }
			sResult +="</tr>";
	   }
	 return sResult;
  }

      public static String getDateTime()
    {
    	SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	java.util.Date Now=new java.util.Date();
    	String NDate=formatter.format(Now);
    	return NDate;
    }
    public static String getStrDate(String DateString){
    	return DateString.substring(0,10);
    }


	public static String getDateTimeYMD()
    {
    	SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd");
    	java.util.Date Now=new java.util.Date();
    	String NDate=formatter.format(Now);
    	return NDate;
    }



	public String[] getValues(HttpServletRequest request, String instr) {
		String[] outstr = request.getParameterValues(instr);
		for (int i = 0; i < outstr.length; i++) {
			if (outstr[i] == null)
				outstr[i] = "";
		}
		return outstr;
	}
	
	public static String getDateYear()
	{
    	SimpleDateFormat formatter=new SimpleDateFormat("yyyy");
    	java.util.Date Now=new java.util.Date();
    	String NDate=formatter.format(Now);
    	return NDate;
	}

	public static String getDateYM()
	{
    	SimpleDateFormat formatter=new SimpleDateFormat("yyyyMMdd");
    	java.util.Date Now=new java.util.Date();
    	String NDate=formatter.format(Now);
    	return NDate;
	}
    /**
     * 将字符串格式化成 HTML 代码输出
     * 只转换特殊字符,适合于 HTML 中的表单区域
     *
     * @param str 要格式化的字符串
     * @return 格式化后的字符串
     */
    public static String toHtmlInput(String str) {
        if (str == null)    return null;

        String html = new String(str);

        html = Replace(html, "&", "&");
        html = Replace(html, "<", "<");
        html = Replace(html, ">", ">");

        return html;
    }

    /**
     * 将字符串格式化成 HTML 代码输出
     * 除普通特殊字符外,还对空格、制表符和换行进行转换,
     * 以将内容格式化输出,
     * 适合于 HTML 中的显示输出
     *
     * @param str 要格式化的字符串
     * @return 格式化后的字符串
     */
    public static String toHtml(String str) {
        if (str == null)    return null;

        String html = new String(str);

        html = toHtmlInput(html);
        html = Replace(html, "\r\n", "\n");
        html = Replace(html, "\n", "<br>\n");
        html = Replace(html, "\t", "    ");
        html = Replace(html, "  ", "  ");

        return html;
    }

    /**
     * 将普通字符串格式化成数据库认可的字符串格式
     *
     * @param str 要格式化的字符串
     * @return 合法的数据库字符串
     */
    public static String toSql(String str) {
		if(str==null){str="";}
        String sql = new String(str);
        return Replace(sql, "'", "''");
    }

	    /**
     * 字符串替换,将 source 中的 oldString 全部换成 newString
     *
     * @param source 源字符串
     * @param oldString 老的字符串
     * @param newString 新的字符串
     * @return 替换后的字符串
     */
    public static String Replace(String source, String oldString, String newString) {
        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();
    }
    
    
    /**
     * 日期比较
     *
     * @param bjrq(比较日期),its(比较天数)
     * @return true为符合条件
     */
    public static boolean getComparDay(Date bjrq,int its)
    {
							boolean bJ=false;
							java.util.Date dqrq=new java.util.Date();
							java.text.SimpleDateFormat ft = new java.text.SimpleDateFormat("yyyy-MM-dd");				
							String sd1=(String)ft.format(dqrq);
							String sd2 =(String)ft.format(bjrq);
							String[] sar1=sd1.split("-");
							String[] sar2=sd2.split("-");
							if(sar1[0].equals(sar2[0])&&sar1[1].equals(sar2[1]))
							{
								int iday=Integer.parseInt(sar1[2])-Integer.parseInt(sar2[2]);						
								if(iday>=its){
								    bJ=false;
								 }else{
								 		bJ=true;
								 }
							}

							else if(sar1[0].equals(sar2[0])&&(!sar1[1].equals(sar2[1])))
							{
									int a1=Integer.parseInt(sar1[2]);//当前日期
									int a2=Integer.parseInt(sar2[2]);//比较日期
									int iday=30-a2+a1;
									if(iday>=its){
									    bJ=false;
									 }else{
									 		bJ=true;
									 }
							}
							return bJ;
	}
	  /**
     * 格式化日期
     *
     * @param 要格式的日期,格式类型
     * @return 格式后的日期
     */
    public static String getFormatDate(Date rq,int ilx)
    {
    		String sRet="";
    		if(ilx==1)
    		{
    			java.text.SimpleDateFormat ft = new java.text.SimpleDateFormat("yyyy-MM-dd"); //格式后输出	
    			sRet=ft.format(rq);			
    		}
    		else if(ilx==2)
    		{
    			SimpleDateFormat ft=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    			sRet=ft.format(rq);
    		}
    		else if(ilx==3)
    		{
    			SimpleDateFormat ft=new SimpleDateFormat("yyyyMMdd");
    			sRet=ft.format(rq);
    		}
    		else if(ilx==4)
    		{
    			SimpleDateFormat ft=new SimpleDateFormat("yyyy-MM");
    			sRet=ft.format(rq);
    		}
    		else if(ilx==5)
    		{
    			SimpleDateFormat ft=new SimpleDateFormat("MM-dd");
    			sRet=ft.format(rq);
    		}	
    		else if(ilx==6)
    		{
    			SimpleDateFormat ft=new SimpleDateFormat("dd");
    			sRet=ft.format(rq);
    		}	
    		return sRet;
    }
    
 	  /**
     * 格式化字符串
     *
     * @param str要截取的字符串,leng要截取的长度
     * @return 格式后的日期
     */
    public static String getMidString(String str,int leng)
    {
    		String sRet="";
    		if(str.length()>leng)
    		{
    				sRet=str.substring(0,leng);
    				sRet+="...";
    		}
    		else{sRet=str;}
    		return sRet;
    }
}

⌨️ 快捷键说明

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