English 中文(简体)
Java 日期对象:日光节省
原标题:Java Date Object : daylight saving

我有一个基于客户服务员的 java 应用程序。 客户正在美国/ 太平洋时区运行, 并在 UTC 服务器运行( 我在保存 UTC 数据库中的时间) 。

例如,如果我将日期保存为 09:00 Hrs 太平洋时间, 它会在 DB 中被保存为 14: 00 Hrs UTC 。

当我从DB读到这个时候, 日光节日被施用, 现在它被转换为8: 00平时, 而不是9: 00时。

因此,在从太平洋时间转换为世界协调时,不考虑日光节约,但在从世界协调时转换为太平洋时,适用时前后不一致。

在 DB 中, 列的类型是时间, 在 Java 中, 我把它读成日期对象 。

我该怎么处理?

问题回答

通常情况下, DB 服务器决定时间, 是否使用日光节省, 以及时区, UTC 是标准值 。

建议:

  1. Maybe you want to set the time by the client side as a string field with another field for the time zone PST, EST, or whatever.
  2. Make a field just for the time zone, and calculate the time for display to the client side.

我认为你所能做的最好的事情是 尽可能多地确保你的时间处理 完全不受时区的影响。例如,自 Unix Epoch 以来的毫升。然后,你只应用时区数据,然后才将数据显示给用户。

因此,在这种情况下, 当您向服务器报告和从服务器检索时, 不要使用任何本地时间假设。 这样, 就不可能有不匹配的时区或 DST 处理数据 。

除此以外,我建议你手工使用 getLong 手动构建日期对象。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签