maple_stephen
Just try to find my memorize...
BlogJava
首頁
新隨筆
聯系
聚合
管理
隨筆-37 評論-58 文章-4 trackbacks-0
java判斷字符串是否是日期
常用的java工具類
1
.
public
class
StringUtil
{
2
.
3
.
/** */
/**
4. * 判斷字符串值是否為空
5. *
@param
value
6. *
@return
7.
*/
8
.
public
static
boolean
isEmpty(String value)
{
9
.
if
(value
==
null
||
""
.equals(value))
{
10
.
return
true
;
11
. }
12
.
return
false
;
13
. }
14
.
15
.
public
static
boolean
isDate(String value,String format)
{
16
.
17
. SimpleDateFormat sdf
=
null
;
18
. ParsePosition pos
=
new
ParsePosition(
0
);
//
指定從所傳字符串的首位開始解析
19
.
20
.
if
(value
==
null
||
isEmpty(format))
{
21
.
return
false
;
22
. }
23
.
try
{
24
. sdf
=
new
SimpleDateFormat(format);
25
. sdf.setLenient(
false
);
26
. Date date
=
sdf.parse(value,pos);
27
.
if
(date
==
null
)
{
28
.
return
false
;
29
. }
else
{
30
. System.out.println(
"
-------->pos :
"
+
pos.getIndex());
31
. System.out.println(
"
-------->date :
"
+
sdf.format(date));
32
.
//
更為嚴謹的日期,如2011-03-024認為是不合法的
33
.
if
(pos.getIndex()
>
sdf.format(date).length())
{
34
.
return
false
;
35
. }
36
.
return
true
;
37
. }
38
. }
catch
(Exception e)
{
39
. e.printStackTrace();
40
.
return
false
;
41
. }
42
. }
43
.
44
.
public
static
void
main(String[] args)
{
45
. System.out.println(isDate(
"
21011-02-18
"
,
"
yyyy-MM-dd
"
));
46
. }
47
. }
posted on 2011-11-15 15:46
楓中玎玲
閱讀(2026)
評論(0)
編輯
收藏
所屬分類:
Java常用
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
import store for website trustcacert
將dom對象轉換成string
java判斷字符串是否是日期
<
2011年11月
>
日
一
二
三
四
五
六
30
31
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
1
2
3
4
5
6
7
8
9
10
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(4)
給我留言
查看公開留言
查看私人留言
隨筆分類
Corba(1)
JavaScript(2)
Java常用(3)
Struts(4)
關于面試(2)
心情日記(2)
數據庫DB(4)
服務器與IDE問題集合(6)
經典轉貼(7)
設計模式(1)
酸甜苦辣,喜怒哀樂(3)
隨筆檔案
2012年11月 (1)
2012年9月 (2)
2011年11月 (2)
2009年12月 (2)
2009年1月 (1)
2008年12月 (1)
2008年11月 (3)
2008年9月 (1)
2008年8月 (2)
2008年7月 (1)
2007年9月 (5)
2007年8月 (2)
2007年7月 (1)
2007年3月 (1)
2006年11月 (2)
2006年10月 (3)
2006年9月 (1)
2006年8月 (3)
2006年7月 (3)
文章分類
錯誤解決之道(1)
文章檔案
2006年8月 (1)
2006年5月 (1)
2006年4月 (1)
2006年3月 (1)
搜索
最新評論
1.?re: ClassNotFoundException: org.hibernate.hql.ast.HqlToken解決之道
多謝多謝,這個問題困擾我兩天了,根本沒想到是jar包的問題
--我太陽額
2.?re: ClassNotFoundException: org.hibernate.hql.ast.HqlToken解決之道
@shimiso
這個官方方法是最好的。謝謝!
--康榮龍
3.?re: ClassNotFoundException: org.hibernate.hql.ast.HqlToken解決之道
@DingDang
這個方法好使
--11
4.?re: ClassNotFoundException: org.hibernate.hql.ast.HqlToken解決之道[未登錄]
@shimiso確實 官方正解
--微笑
5.?re: ClassNotFoundException: org.hibernate.hql.ast.HqlToken解決之道[未登錄]
請問那個文件在哪能找到?非常感謝@DingDang
--啦啦啦
閱讀排行榜
1.?JSEclipse的下載(8359)
2.?【轉貼】應屆畢業生面試技巧(5464)
3.?JSTL的fn函數(4824)
4.?Tomcat 啟動和關閉時關于Apache Portable Runtime的錯誤信息解決辦法(3556)
5.?解析文件時遇到The reference to entity "ibudnr" must end with the ';' delimiter.(2647)
評論排行榜
1.?【轉貼】應屆畢業生面試技巧(7)
2.?JSEclipse的下載(3)
3.?第一個corba的Hello World~(3)
4.?Tomcat 啟動和關閉時關于Apache Portable Runtime的錯誤信息解決辦法(2)
5.?JSTL的fn函數(2)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 楓中玎玲
主站蜘蛛池模板:
广水市
|
济宁市
|
雷州市
|
贵阳市
|
集贤县
|
大丰市
|
武穴市
|
岑溪市
|
洛隆县
|
淮阳县
|
舞钢市
|
东宁县
|
高雄县
|
吉木萨尔县
|
泊头市
|
湟源县
|
祁阳县
|
呼玛县
|
峨眉山市
|
东乡县
|
宁晋县
|
临邑县
|
建宁县
|
绥江县
|
盱眙县
|
林芝县
|
定州市
|
宁都县
|
三台县
|
环江
|
扶余县
|
洪泽县
|
泉州市
|
安徽省
|
东兴市
|
卫辉市
|
巴彦县
|
满城县
|
静宁县
|
淮阳县
|
民县
|