11

I was trying to make a GWT application. Then I got some errors when using SimpleDateFormat class in client and shared side.

[ERROR] [gwtfirst] Line 381: No source code is available for type java.text.SimpleDateFormat; did you forget to inherit a required module?

following is my code in client side:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
Window.alert(sdf.format(usersList.get(30).getCreatedate()));

But I can use SimpleDateFormat with server side... I'm wondering if I can't use SimpleDateFormat in client or shared side?

3 Answers 3

25

SimpleDateFormat is not available in GWT. Use com.google.gwt.i18n.client.DateTimeFormat instead.

1
  • @tibtof you're right. Just a little addition for Mozzan - you CAN use SimpleDateFormat on the server side. Just not on the client side.
    – mlkammer
    Aug 9, 2013 at 14:39
3

GWT does not contain SimpleDateFormat instead it have DateTimeFormat So you can use

 DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("YYYY/MM/DD") 
 Date date = dateTimeFormat.parse(str);

for more read "com.google.gwt.i18n.client.DateTimeFormat".

0

I dont know if that is the problem with my code though, because it has been working all day until now. I never changed that code... just stopped compiling....

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.