I have a bunch of timestamp fields in my 开发者_如何学Pythonjava model bean which is sent the view. If a user in another country or timezone tries to view these fields, will they be shown in the user's timezone. If not, could you provide a code snippet to do this conversion to the users timezone.
[Update] Adeels reply below will work, and this following link shows how to set it when getting the bean from database itself.
Get the user's time zone, and use Calendar.setTimeZone()
to set the time zone and retrieve the Timestamp
according to the user's time zone. You can instantiate Calendar
using that TimeZone
, i.e.
Calendar cal = GregorianCalendar.getInstance(userTimeZone);
Or you can set it afterwards like,
Calendar cal = Calendar.getInstance();
cal.setTimeZone(userTimeZone);
精彩评论