简体   繁体   English

如何在Web应用程序中维护唯一时区

[英]How to maintain a unique timezone across web application

I have requirement in my enterprise web application to maintain a unique time zone (say EST). 我在企业Web应用程序中要求维护一个唯一的时区(例如EST)。 All the timestamp what we display and store in database should be in EST only. 我们在数据库中显示和存储的所有时间戳都应仅在EST中。 I am using Spring MVC/Hibernate for my web application. 我在Web应用程序中使用Spring MVC / Hibernate。 Is there any best practices or suggestion how to implement this feature? 有什么最佳实践或建议如何实现此功能? Any suggestions or guidance would be of great help. 任何建议或指导都会有很大帮助。

My suggestion is to set the timezone in the initialization script which creates the java process using the argument -Duser.timezone=NAME where NAME you can find in the list below: 我的建议是在初始化脚本中设置时区,该脚本使用参数-Duser.timezone = NAME创建Java进程,其中NAME可以在下面的列表中找到:

https://en.wikipedia.org/wiki/List_of_tz_database_time_zones https://zh.wikipedia.org/wiki/List_of_tz_database_time_zones

Note1: Unfortunately, the developer can create some objects like Calendar using a different TimeZone. 注意1:不幸的是,开发人员可以使用其他TimeZone创建某些对象,例如Calendar。 For those cases you can use Java Security Polices (it will be hard to setup for a application server). 在这种情况下,您可以使用Java安全策略(很难为应用程序服务器设置)。 But I think just configuring that is pretty enough. 但是我认为仅配置就足够了。

Note2 : By default the JVM collects the timezone from the user environment. 注意2:默认情况下,JVM从用户环境收集时区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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