我需要将服务器时间转换为用户的时间,具体取决于他们的时区.
这是通过使用HttpServletRequest对象来确定其时区的最佳方法吗?
Locale clientLocale = request.getLocale();
Calendar calendar = Calendar.getInstance(clientLocale);
TimeZone clientTimeZone = calendar.getTimeZone();
Run Code Online (Sandbox Code Playgroud) 在Web请求对象中获取时区信息有一个新功能.请参阅http://docs.spring.io/spring/docs/4.0.x/spring-framework-reference/html/mvc.html#mvc-timezone中的 16.9.1部分
但是我无法解决我们如何从请求中获取时区信息或者我应该使用哪种方法来获取时区信息?
查看和关注源代码后,请访问https://github.com/spring-projects/spring-framework/blob/v4.0.7.RELEASE/spring-webmvc/src/main/java/org/springframework/web/servlet/ support/RequestContext.java#L242,我试图手动打印
println WebUtils.getSessionAttribute(request, SessionLocaleResolver.class.getName() + ".TIME_ZONE")
Run Code Online (Sandbox Code Playgroud)
有帮助吗?