2015-07-10 40 views
1

我無法驗證用戶使用java和selen輸入日期的格式。使用java和selen驗證輸入日期的格式

SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM dd"); 
    Date date = new SimpleDateFormat("dd-MM-yyyy").parse(UserInput); 

我覺得這樣會被使用但是不能弄清楚怎麼做? 我要檢查該日在網站上爲MMMM dd格式

+0

你爲什麼不使用你剛剛創建解析輸入的日期格式? – cvesters

+0

我已經嘗試過了,但它有問題,它可以在6個月和7月等4個字母的月份內正常工作,但對於其他人,我必須將M的數量與當月拼寫中的字母數量相加。 – Rkstr22

+0

如果你以月份的名字存在M的數量會怎麼樣? – cvesters

回答

1

此代碼工作正常,我:

final DateFormat format = new SimpleDateFormat("MMMM dd"); 
final Date d = format.parse("August 27"); 
+0

好吧我會試試 – Rkstr22

+0

它不適合我 – Rkstr22