SQL oracle如何将日期保存为24小时格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8162566/
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
How to save date into 24 hours format in oracle
提问by laxmanperamalla
I am new to Oracle, and I need to save date and time in an Oracle database.
我是 Oracle 的新手,我需要在 Oracle 数据库中保存日期和时间。
I am using time stamp as datatype for row. But now my problem is it saves date and time in 12 hours format like this 17/11/2011 10:10:10 PM
.
我使用时间戳作为行的数据类型。但现在我的问题是它像这样以 12 小时格式保存日期和时间17/11/2011 10:10:10 PM
。
But I need it in 24 hours format like 17/11/2011 22:10:10
. I didn't understand the results that Google search result provided. Can any one please help me by posting some code.
但我需要 24 小时格式,如17/11/2011 22:10:10
. 我不明白 Google 搜索结果提供的结果。任何人都可以通过发布一些代码来帮助我。
回答by Justin Cave
Oracle always stores timestamps (and dates) in a packed binary format that is not human readable. Formatting is done only when a timestamp (or a date) is converted to a string.
Oracle 始终以人类不可读的打包二进制格式存储时间戳(和日期)。仅当时间戳(或日期)转换为字符串时才会进行格式化。
You can control the formatting of your output by coding an explicit to_char
. For example
您可以通过编码显式to_char
. 例如
SELECT to_char( your_timestamp_column, 'DD/MM/YYYY HH24:MI:SS' )
FROM your_table