?? format.java
字號:
package net.acai.util;/** * Title: 清清網絡 * Description: * Copyright: Copyright (c) 2002 * Company: www.qingqing.com * @author: qingqing * @version 1.0 */import net.acai.util.*;import java.text.SimpleDateFormat;import java.text.*;import java.util.Date;/** * Title: 清清網絡 * Description: * Copyright: Copyright (c) 2002 * Company: 211.68.39.120、webcpu.51.net * @author qingqing * @version 1.0 */public class Format { 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 getStrDateTime(){ return StringUtils.replace(StringUtils.replace(StringUtils.replace(getDateTime(),":",""),"-","")," ",""); } public static boolean compareTo(String last,String now){ try{ DateFormat formatter=DateFormat.getDateInstance(); Date temp1=formatter.parse(last); Date temp2=formatter.parse(now); if(temp1.after(temp2)) return false; else if(temp1.before(temp2)) return true; } catch(ParseException e) { e.printStackTrace(); } return false; } /** * 字符串替換,將 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(); } /* public static String ReplaceIgnoreCase(String source, String oldString, String newString) { } */ /** * 將字符串格式化成 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) { String sql = new String(str); return Replace(sql, "'", "''"); } /* public static void main(String[] args) { String s = "<html> ddd"; Format f = new Format(); } */}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -