简体   繁体   English

如何在iSeries上的SQL400中获得UTC时间戳?

[英]How can I get a UTC timestamp in SQL400 on iSeries?

Our iSeries (aka AS400, aka i5, aka SystemI) runs in local time, but we have an application, that uses UTC (written in Java, connected by JDBC to the iSeries DB). 我们的iSeries(又名AS400,又名i5,又名SystemI)在当地时间运行,但是我们有一个应用程序,它使用UTC(用Java编写,通过JDBC连接到iSeries DB)。

How can I generate UTC-timestamps via SQL on that system? 如何在该系统上通过SQL生成UTC时间戳?

DB2/400 (which likes to be different in details from other DB2 flavours), has a special register called CURRENT TIMEZONE . DB2 / 400(喜欢在细节上不同于其他DB2口味)具有一个称为CURRENT TIMEZONE的特殊寄存器。 It contains a numeric value, that can be subtracted from a timestamp or time value. 它包含一个数值,可以从时间戳或时间值中减去该数值。

In an example query: 在一个示例查询中:

SELECT 
    CURRENT TIMESTAMP AS local, 
    CURRENT TIMEZONE AS offset, 
    CURRENT TIMESTAMP - CURRENT TIMEZONE AS utc
FROM SYSIBM.SYSDUMMY1

Gives you something like: 给您类似的东西:

+----------------------------+--------+----------------------------+
| LOCAL                      | OFFSET | UTC                        |
+----------------------------+--------+----------------------------+
| 2014-05-27 14:09:19.127339 | 20.000 | 2014-05-27 12:09:19.127339 |
+----------------------------+--------+----------------------------+

Notes: 笔记:

  • This example has an offset of +2 hours for central European summer time. 本示例中欧夏令时的偏移量为+2小时。
  • SYSIBM.SYSDUMMY1 is a special table supplied by IBM, with the sole purpose of having exactly one row with exactly one column. SYSIBM.SYSDUMMY1是IBM提供的特殊表,其唯一目的是使一行恰好具有一列。
  • Things like NOW() - CURRENT TIMEZONE and CURRENT TIME - CURRENT TIMEZONE work as well. NOW() - CURRENT TIMEZONECURRENT TIME - CURRENT TIMEZONE工作。
  • Reference in IBM's iSeries information center IBM iSeries信息中心中的参考

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

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