Mayank Pandya
Mayank Pandya

Reputation: 1623

Util and sql date conversion in GWT,

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.

Upvotes: 0

Views: 1262

Answers (2)

appbootup
appbootup

Reputation: 9537

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

Upvotes: 0

burna
burna

Reputation: 2962

You can use DateTimeFormat to convert between the representations.

Upvotes: 1

Related Questions