2

I want to check if a given string is in a particular dateformat. If not user should be able to throw error message.

DateTimeFormat format=DateTimeFormat.getFormat("yyyy-MM-dd");               
Date d= format.parse("1990-10-");

with this input , it should give error. I tried with try and catch , but its not throwing any exception.

1
  • Ofcourse, there's no way to know if for example 2013-08-12 is in the format yyyy-MM-dd (12 August 2013) or yyyy-dd-MM (8 December 2013). Commented Aug 12, 2013 at 7:29

2 Answers 2

5

Use the class

http://www.gwtproject.org/javadoc/latest/com/google/gwt/i18n/shared/DateTimeFormat.html#parse(java.lang.String)

Which is in shared package.

Not the clinet package class

http://www.gwtproject.org/javadoc/latest/com/google/gwt/i18n/client/DateTimeFormat.html#parse(java.lang.String)

Sign up to request clarification or add additional context in comments.

Comments

2

Use java.text.SimpleDateFormat, it throws ParseException.

SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");               
try {
  Date d= format.parse("1990-10-");
} catch (ParseException e) {
 ...
}

8 Comments

No,GWT won't support it.
yup, GWT client side does not support it
That's not GWT's point to implement the whole JVM in Javascript. Thus only a limited part of the Java standard libraries is available in the client.
And, no offence, but maybe you shouldn't answer GWT related questions if you have never worked with it :)
For classes in java.text to be handled correctly, there are megabytes of properties files that would need to be compiled in - in many cases it isn't possible to test if they will actually be used or not because they are parsed and used at runtime.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.