forked from maxliaops/Java_Web_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChange.java
More file actions
55 lines (53 loc) · 1.4 KB
/
Change.java
File metadata and controls
55 lines (53 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.toolsBean;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Change {
public static String htmlSetChange(String source){
String changeStr="";
changeStr=source.replace("&","&");
changeStr=changeStr.replace(" "," ");
changeStr=changeStr.replace("<","<");
changeStr=changeStr.replace(">",">");
changeStr=changeStr.replace("\r\n","<br>");
return changeStr;
}
public static String toChinese(String source){
if(source==null)
source="";
try {
source=new String(source.getBytes("ISO-8859-1"),"gb2312");
} catch (UnsupportedEncodingException e) {
source="";
e.printStackTrace();
}
return source;
}
public static String dateTimeChange(Date date){
String strDate="";
if(date!=null){
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
strDate=format.format(date);
}
return strDate;
}
public static String getSerial(Date date){
String strDate="";
if(date!=null){
SimpleDateFormat format=new SimpleDateFormat("MMddyyyyHHmmss");
strDate=format.format(date);
}
return strDate;
}
public static int strToInt(String src){
if(src==null||src.equals(""))
src="-1";
int result=-1;
try{
result=Integer.parseInt(src);
}catch(NumberFormatException e){
e.printStackTrace();
}
return result;
}
}