Struts2日期标记TimeZone行为 [英] Struts2 Date Tag TimeZone behavior

查看:196
本文介绍了Struts2日期标记TimeZone行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用struts2的< s:date> 标记。

I am using <s:date> tag of struts2.

转换存储的日期 04/09/2014 11:40:17 在UTC时间到 IST 时间我使用struts2 日期标记如下:

To convert a date stored 04/09/2014 11:40:17 in UTC time to IST time I used struts2 date tag as belows :

<s:date name = "dateregistered" 
      format = "MM/dd/yyyy HH:mm:ss a" 
    timezone = "GMT+5.30" />

它总是给我日期: 04/09/2014 06:上午10:17

预期结果应为: 04/09/2014 05:10:17 PM

我没有得到我错的地方并且犯了错误,我正在使用 hibernate 来获取和 java.util.date 用于存储上面使用的值

I am not getting where I am wrong and doing mistake,I am using hibernate to fetch and java.util.date to store the value which is used above

数据存储和检索的过程:

我通过hibernate将值存储在mysql中:

I stored value in mysql through hibernate:

TimeZone.setDefault(TimeZone.getTimeZone("Etc/UTC"));
user.setCreatedDateTime(new java.util.Date());
...
...
...

现在我从DB获得的值为 04/09/2014 11:40:17 。当我执行此插入时,实际时间 04/09/2014 05:10:17 PM IST 。因此,它清除了存储在数据库中的时间是UTC时间。

Now I am getting the value from DB as 04/09/2014 11:40:17 . When I performed this insertion the actual time was 04/09/2014 05:10:17 PM IST . So it clears that the time being stored in DB is UTC time.

现在我正在重新计算时间并在键值对中设置为地图.put(dateregistered,c.getCreatedDateTime());

Now I am retriving time and setting in map in key value pair as map.put("dateregistered",c.getCreatedDateTime());

user.getCreatedDateTime()

并使用上面提到的struts 2标签检索值

and retrieving value using struts 2 tag as mentioned above

推荐答案


  1. 使用而不是作为分隔符;

  2. 添加前导 0

  1. Use : instead of . as separator;
  2. Add a leading 0.

IST(印度标准时间)的正确TimeZone UTC + 05:30 ,然后 GMT + 05:30 ;

<s:date name = "dateregistered" 
      format = "MM/dd/yyyy HH:mm:ss a" 
    timezone = "GMT+05:30" />

这篇关于Struts2日期标记TimeZone行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆