I am using <s:date> 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 :

<s:date name = "dateregistered" 
      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

有帮助吗?

解决方案

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

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

<s:date name = "dateregistered" 
      format = "MM/dd/yyyy HH:mm:ss a" 
    timezone = "GMT+05:30" />
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top