In JSF - Getting the Client's Locale (To Display time in browser's timezone)

后端 未结 6 2104
失恋的感觉
失恋的感觉 2020-12-28 10:03

I\'m writing a webapp in JSF 2.0 that displays Timestamps as part of the information to the user. I would like the user to see the timestamps localized to their location (br

6条回答
  •  感情败类
    2020-12-28 10:45

    You may want to try jsTimezoneDetect to detect timezone on the client side and send to the server.

    UPDATE: to get a user's Locale, you can try the following:

    HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
    Locale locale = request.getLocale();
    

    Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns an Enumeration containing one Locale, the default locale for the server.

提交回复
热议问题