【问题标题】:select date+time+timezone with oracle db使用 oracle db 选择日期+时间+时区
【发布时间】:2012-10-27 16:06:09
【问题描述】:

我想获取以下格式的日期:

2009-01-15T09:13:51.0Z

我使用以下语句:

SELECT to_char(sysdate, 'YYYY-mm-DD HH24:MI:SS.') 

但是返回:

2012-11-07 16:12:00.

如何在中间添加T,在末尾添加0Z

这是可能的还是我必须使用连接?

【问题讨论】:

标签: database oracle date


【解决方案1】:

to_char((sysdate,''YYYY-mm-DD HH24:MI:SS TZD') 返回用户计算机上的缩写时区。如果是另一个时区,您需要从自己的时区中添加/减去小时数才能得到当前时区的时间正确。有一个带有时区数据的 oracle 格式。 而不是将列设为日期,您可以将其设为以下 sql 类型之一

Type TIMESTAMP adds miliseconds but no timezone.
Type TIMESTAMP WITH TIMEZONE same as timestamp but with timezone it was saved with.
Type TIMESTAMP WITH LOCAL TIMEZONE same as timestamp but all is saved in local timezone.

【讨论】:

    【解决方案2】:

    用双引号括起来。

    to_char(sysdate, 'YYYY-mm-DD"T"HH24:MI:SS."0Z"')
    

    【讨论】:

      猜你喜欢
      • 2015-07-16
      • 2016-12-30
      • 1970-01-01
      • 2015-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-08
      • 1970-01-01
      相关资源
      最近更新 更多