oracle 使用oracle db选择日期+时间+时区
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13272463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
select date+time+timezone with oracle db
提问by jobe
I would like to get a date with the following format:
我想获得以下格式的日期:
2009-01-15T09:13:51.0Z
2009-01-15T09:13:51.0Z
I use the following statement:
我使用以下语句:
SELECT to_char(sysdate, 'YYYY-mm-DD HH24:MI:SS.')
But that returns:
但这会返回:
2012-11-07 16:12:00.
2012-11-07 16:12:00。
How can I ad the T
in the middle and 0Z
at the end?
我怎样才能T
在中间和0Z
最后做广告?
Is this possible or do I have to use concatenation?
这是可能的还是我必须使用串联?
回答by DazzaL
put it in double quotes.
把它放在双引号中。
to_char(sysdate, 'YYYY-mm-DD"T"HH24:MI:SS."0Z"')
回答by user2225399
to_char((sysdate,''YYYY-mm-DD HH24:MI:SS TZD') returns the abbreviated timezone on the users computer. If another timzone is you will need to add/subtract hours from your own timezone to get time correct in current timezone. There is an oracle format with timezone data. rather than making column a date you can make it one of the following sql types
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.