格式化字段
时间:2014-05-09 00:05:49
收藏:0
阅读:532
|
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 |
package
FormatData;import java.text.DateFormat;import java.util.regex.Matcher;import java.util.regex.Pattern;import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;public class FormatData { private
static final Pattern intPattern = Pattern.compile("\\d+(\\.\\d{0,2})?"); //1. 字符串转化为数字 public
static float getFloatValue(String value) { Matcher matcher = intPattern.matcher(value); if
(matcher.find()) { return
Float.valueOf(matcher.group()); } return
0.0f; } //2. 比较日期 public
static boolean isDateBefore(String date1, String date2) throws
java.text.ParseException { try
{ DateFormat df = DateFormat.getDateTimeInstance(); boolean
result = df.parse(date1).before(df.parse(date2)); return
result; } catch
(ParseException e) { System.out.println(e.getMessage()); return
false; } }} |
评论(0)