java中struts2日期,Struts2日期标记TimeZone行为

I am using tag of 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 :

format = "MM/dd/yyyy HH:mm:ss a"

timezone = "GMT+5.30" />

and it always give me the date: 04/09/2014 06:10:17 AM.

The expected result should be: 04/09/2014 05:10:17 PM.

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

The process how data was stored and retrived:

I stored value in mysql through hibernate:

TimeZone.setDefault(TimeZone.getTimeZone("Etc/UTC"));

user.setCreatedDateTime(new java.util.Date());

...

...

...

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.

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

user.getCreatedDateTime()

and retrieving value using struts 2 tag as mentioned above

解决方案

Use : instead of . as separator;

Add a leading 0.

The right TimeZone for IST (Indian Standard Time) is UTC+05:30, then GMT+05:30;

format = "MM/dd/yyyy HH:mm:ss a"

timezone = "GMT+05:30" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值