I am using display tag for table details i want to change date & time to user's local browser setting, Data in DB is UMT. IF user is from india then it will add +5:30 etc. How can i do this. I am stuck in this. Please help me.
Asked
Active
Viewed 802 times
2 Answers
0
Have you tried like this ??
Locale cLoc=request.getLocale();
Calendar cCal=Calendar.getInstance(cLoc);
TimeZone tz=cCal.getTimeZone();
//......

Suresh Atta
- 120,458
- 37
- 198
- 307
-
Thankyou very much for reply.. But how can i implement it in display tag column. My data comes from resultset. Please suggest. Please provide any code snippets. – Raj Vaishnav Mar 05 '13 at 06:05
-
Sorry,Did'nt use display tag before.Findout a way to pass parameter to that or call a method inside the display tag.But the above lines of code working perfectly in jsp. – Suresh Atta Mar 05 '13 at 06:15
0
A bit late to the party, but still answer here in case anyone else needs it.
Display.tag uses MessageFormatColumnDecorator
internally to apply MessageFormat
formatter to all columns that have "format" parameter set.
So, your options are:
- Create your own custom
MessageFormatColumnDecorator
. Unfortunatelly it is inined in theColumnTag
code and cannot be very easily replaced (decorators are chained), so you will have to compile your own copy of Display.Tag jar, with your custom decorator in it.
In your custom decorator use the following sample code to change MessageFormat
's timezone:
TimeZone tz = //get your timezone here
Object [] formats = format.getFormats(); //'format' is MessageFormat instance
for (int i = 0; i < formats.length; i++) {
if (formats[i] instanceof SimpleDateFormat) {
((SimpleDateFormat)formats[i]).setTimeZone(tz);
}
}
- Second option is to use the
<fmt:formatDate>
within Display.tag column tags to format the output.
Sample Code:
<display:table name="dateList" id="object">
<display:column title="Date">
<fmt:formatDate value="${object.date}" type="both" dateStyle="long" timeStyle="long"/>
</display:column>
</display:table>
You can set default request locale for <fmt:formatDate>
or wrap them in <fmt:timeZone>
tag to set a timezone for them to use.

Aramir
- 317
- 2
- 9