Spring mvc:如何为每个用户设置时区?
我的数据库中的数据存储为 UTC。
每个用户的设置中都有时区。如何在显示和保存过程中处理时区转换?
I have data in database stored in UTC.
Every user has timezone in his setting. How can I handle timezone conversion during display and save?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Spring 没有像对语言环境那样内置对此的支持。有一个 ticket 请求此功能,但它自 2005 年以来就已存在。
如果您是使用 JSP,您可以使用 fmt:timeZone 标签设置要在任何嵌套 fmt:formatDate 标签上使用的时区。
Spring does not have built-in support for this like they do for locales. There is a ticket requesting this functionality but it has been been around since 2005.
If you are using JSP, you can use the fmt:timeZone tag to set the timezone to be used on any nested fmt:formatDate tags.
为您的 Date 对象提供一个转换器/PropertyEditor 来实现这一点(在转换为字符串进行显示时应用用户时区,在转换回日期进行处理时应用 UTC 时区)难道不会有帮助吗?
Wouldn't it help to have a converter / PropertyEditor for your Date objects that does exactly that (applies the user timezone when converting to String for displaying and the UTC timezone when converting back to a Date for processing) ?