在Java ee应用程序中使用日期时间[重复]

时间:2021-05-15 16:59:07

This question already has an answer here:

这个问题在这里已有答案:

Here is the problem. It is bit complicated to explain. I'll try my best.

这是问题所在。解释起来有点复杂。我会尽力的。

I have an application which has and administration portal and a user portal. This application is pretty old and done in java ee using struts framework. The db id oracle MySQL.

我有一个应用程序,它有管理门户和用户门户。这个应用程序非常陈旧,使用struts框架在java ee中完成。 db id oracle MySQL。

It is a tendering system so the time is very important. In administration portal when creating tenders and comparing publish/start/closing dates Server time is used. And in user portal it uses the machine time.

这是一个招标系统,所以时间非常重要。在管理门户中创建投标并比较发布/开始/结束日期时使用服务器时间。在用户门户中,它使用机器时间。

This application is to be used by users in different time zones.

此应用程序将由不同时区的用户使用。

So I thought if using GMT time. But then i will have to change every thing fron creating tenders and saving in database and retrieving and converting and all.

所以我想如果使用GMT时间。但是,我将不得不改变所有事情,从创建招标和保存数据库,检索和转换等等。

So is there any standard mechanism to handle time in a situation like this. Please also suggest me some links to refer and if anyone can help me with that is a great thing.

那么在这种情况下是否有任何标准机制来处理时间。还请建议我一些链接,如果有人可以帮助我,这是一件好事。

1 个解决方案

#1


1  

You're right in thinking to store the date in GMT format. You'll have to understand the context, specifically meaning time zone. So it's always preferable to bring them to your local time zone before comparison as in case with your administration portal.

你想以GMT格式存储日期是对的。您必须了解上下文,特别是时区。因此,在进行比较之前,最好将它们带到您当地的时区,就像您的管理门户一样。

Now, coming to user portal where you have different user time zone, its better to have the GMT date sent as is and you'll need a way to get the user time zone and format to appropriate time zone before displaying it to the user.

现在,进入具有不同用户时区的用户门户,最好按原样发送GMT日期,并且您需要一种方法将用户时区和格式设置为适当的时区,然后再将其显示给用户。

#1


1  

You're right in thinking to store the date in GMT format. You'll have to understand the context, specifically meaning time zone. So it's always preferable to bring them to your local time zone before comparison as in case with your administration portal.

你想以GMT格式存储日期是对的。您必须了解上下文,特别是时区。因此,在进行比较之前,最好将它们带到您当地的时区,就像您的管理门户一样。

Now, coming to user portal where you have different user time zone, its better to have the GMT date sent as is and you'll need a way to get the user time zone and format to appropriate time zone before displaying it to the user.

现在,进入具有不同用户时区的用户门户,最好按原样发送GMT日期,并且您需要一种方法将用户时区和格式设置为适当的时区,然后再将其显示给用户。