Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个纪元时间(秒)。它向我展示了不同的时间JAVA,当我这样做时
JAVA
new Date(time*1000)
当我这样做时,在 SQL 中
SELECT cast((DATE '1970-01-01' + time/24/60/60) as timestamp) from dual.
SELECT cast((DATE '1970-01-01' + time/24/60/60) as timestamp) from dual
问题主要是,我需要凌晨 2 点到凌晨 4 点之间特定间隔的数据。因此,当我将秒值传递给 SQL 查询时。它将其解释为上午 9 点到 11 点之间。我知道这是因为时区差异。
我该如何克服这个问题?
尝试改用时间戳:
SELECT cast((TIMESTAMP '1970-01-01 00:00:00.00' + time/24/60/60) as timestamp) FROM dual
演示:http ://www.sqlfiddle.com/#!4/d41d8/1465
我对处理任何时区相关问题的建议是始终在内部将时间处理为 UTC,并将它们作为 UTC 存储在数据存储中。仅将它们转换为本地时间以显示给用户。