简体   繁体   English

GWT中的Util和sql日期转换,

[英]Util and sql date conversion in GWT,

Which is the best way for converting Util date to SQL date and vice-versa in GWT? 在GWT中,将Util日期转换为SQL日期,反之亦然的最佳方法是什么? I have sql date in the format "yyyy-MM-dd hh:mm:ss" and also store it in same format. 我的SQL日期格式为“ yyyy-MM-dd hh:mm:ss”,并以相同的格式存储。

您可以使用DateTimeFormat在表示之间进行转换。

Basic Principles - 基本原则 -

  1. You can use SQL Date in GWT client. 您可以在GWT客户端中使用SQL Date。 However be careful about what apis get supported. 但是请注意支持哪些api。 https://developers.google.com/web-toolkit/doc/latest/RefJreEmulation#Package_java_sql 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 ) 您可以在服务器端在它们之间进行转换,以将Sql Date转换为Util Date(确保您使用Calendar / Timezone并且不会丢失时间戳信息)
  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. 如果需要显示它们,请创建自己的DateWrapper pojo,将日历/时区信息与Util日期一起表示为字符串。 How to use java.util.Calendar in GWT 如何在GWT中使用java.util.Calendar
  4. Use DateTimeFormat to manipulate display patterns. 使用DateTimeFormat操作显示模式。
  5. Ignore the deprecated api warning. 忽略已弃用的api警告。 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. 如果您尝试支持多种日期类型hijri,julian,gregorian ...,则将信息填充到DateWrapper中。

java.util.Date vs java.sql.Date java.util.Date与java.sql.Date

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM