简体   繁体   中英

How to change TimeZone based on user TimeZone

I would like to use different TimeZone base on the User's TimeZone .

Question : Is there any feature to set default in JSF or Seam ? It will be effect the whole application.

I hope, the feature will be effect s:convertDateTime , f:convertDateTime , p:calendar , etc... every time I use without using timezone attribute.

I also tried to use Seam component TimeZoneSelector as below.

@In
private TimeZoneSelector timeZoneSelector;
....
timeZoneSelector.setTimeZone(user.getTimeZone());

But, it does not effect on <f:convertDateTime pattern="hh:mm a"/> automatically. I have to retrieve TimeZone form backing bean again.

<f:convertDateTime pattern="hh:mm a" timeZone="#{mybean.timeZone}"/>

JSF does not have default special feature allows you this. You need to take the implementation of this functional.

1- create a default converter for java.util.Date

2- in the the getAsString and getAsObject have the converter retrieve the user timezone from the session

3- use SimpleDateFormat.setTimezone() before parsing/formatting

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM