0

Which is the best way for converting Util date to SQL date and vice-versa in GWT? I have sql date in the format "yyyy-MM-dd hh:mm:ss" and also store it in same format.

Mayank Pandya
  • 1,593
  • 2
  • 17
  • 40
  • I'm not sure what your question is. Because converting Util date to SQL date has nothing to do with the format. And converting isn't a problem, see http://stackoverflow.com/questions/530012/how-to-convert-java-util-date-to-java-sql-date. So I'm assuming your question is more about which one you should use? – Hilbrand Bouwkamp Dec 29 '12 at 12:06

2 Answers2

1

You can use DateTimeFormat to convert between the representations.

burna
  • 2,932
  • 18
  • 27
  • Thanks for reply. but I want to know proper way which is best. I heard also about java.sql.TimeStamp also. – Mayank Pandya Dec 28 '12 at 20:32
  • @burna Not true, both `java.sql.Date` and `java.sql.Timestamp` are part of the GWT jre library and can be used on the client side: http://code.google.com/p/google-web-toolkit/issues/detail?id=87 – Hilbrand Bouwkamp Dec 29 '12 at 11:58
0

Basic Principles -

  1. You can use SQL Date in GWT client. However be careful about what apis get supported. https://developers.google.com/web-toolkit/doc/latest/RefJreEmulation#Package_java_sql
  2. You can convert between them on server side to transform Sql Date to Util Date ( ensure you use Calendar/Timezone and do not lose time stamp information )
  3. Calendar will not be available on Client side. If you need them for display create your own DateWrapper pojo represent the Calendar/Timezone information as string along with Util date. How to use java.util.Calendar in GWT
  4. Use DateTimeFormat to manipulate display patterns.
  5. Ignore the deprecated api warning. Ugly and we are stuck with it.
  6. If you are trying to support mulitple date types hijri, julian, gregorian... you stuff the information in the DateWrapper.

java.util.Date vs java.sql.Date

Community
  • 1
  • 1
appbootup
  • 9,537
  • 3
  • 33
  • 65
  • `1.` seems to be incorrect - from https://developers.google.com/web-toolkit/doc/1.6/RefJreEmulation#Package_java_sql both `java.sql.Date` and `java.sql.Timestamp` are supported, as well as `java.sql.Time`. – Colin Alworth Dec 31 '12 at 21:39