2012-12-16 81 views
0

任何人都可以告诉我如何在GWT中进行日期验证。即时通过日期作为字符串。它应该被转换为日期格式并且其格式将被验证。GWT - 验证日期

+1

哪种语言? Java,C++,C#? – user35443

+1

@ user35443 GWT编程语言是java! –

+0

你为什么要验证转换后的字符串? –

回答

0

可以使用GWT Bean Validation模式匹配表达式字符串:

@Pattern(regexp = "some javascript regular expression") 
private String dateStr; 

或此当你有日期:

@DateTimeFormat(pattern = "dd.MM.yy") 
private Date myStartDate; 

我不使用这个,但你可以看到在gwt-完整的示例2.5.0 samples目录。

祝您有美好的时光。

5
import com.google.gwt.i18n.client.DateTimeFormat; 

... 
DateTimeFormat myDateTimeFormat = DateTimeFormat.getFormat(...); 
Date date = myDateTimeFormat.parseStrict(dateString); 

parseStrict()对无效日期字符串抛出IllegalArgumentException。