如何将“2016-07-01 01:12:22 PM"转换为“2016-07-01 13:12:22"

How to convert #39;2016-07-01 01:12:22 PM#39; to #39;2016-07-01 13:12:22#39; hour format?(如何将“2016-07-01 01:12:22 PM转换为“2016-07-01 13:12:22小时格式?)
本文介绍了如何将“2016-07-01 01:12:22 PM"转换为“2016-07-01 13:12:22"小时格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

谁能帮助我如何在 PL/SQL 中将 2016-07-01 01:12:22 PM 转换为 2016-07-01 13:12:22?我使用了以下但没有运气.

Can anyone help me how to convert 2016-07-01 01:12:22 PM to 2016-07-01 13:12:22 in PL/SQL? I used the following but no luck.

SELECT TO_TIMESTAMP ('08-FEB-19 06.41.41.000000 PM', 'DD-Mon-RR HH24:MI:SS.FF') 
FROM dual

我预计:08-FEB-19 18.41.41.000000

I expect: 08-FEB-19 18.41.41.000000

我收到以下错误:

ORA-01830:日期格式图片在转换整个输入字符串之前结束

ORA-01830: date format picture ends before converting the entire input string

推荐答案

您当前的时间戳没有任何意义,因为它指定的时间为 18 小时,即下午 6 点,但随后它也指定了AM 子午线指示器,表示早于中午.因此,您可以从 TO_TIMESTAMP 模式中删除 AM:

Your current timestamp makes no sense, because it specifies the time as 18 hours, which is 6pm, but then it also specifies the AM meridian indicator, which means earlier than noon. So, you may remove the AM from your TO_TIMESTAMP pattern:

SELECT TO_TIMESTAMP ('08-FEB-19 18.41.41.000000', 'DD-Mon-RR HH24.MI.SS.FF')
FROM dual;

08-FEB-19 06.41.41.000000000 PM

请注意,Oracle 内部确实没有 12 或 24 小时格式时间戳之类的东西.相反,如果您想以 24 小时格式查看您的 Oracle 时间戳,您可以使用适当的 24 小时格式掩码调用 TO_CHAR 之类的操作:

Note that there is really no such thing as 12 or 24 hour format timestamp internally in Oracle. Rather, if you want to view your Oracle timestamp in 24 hour format, you may do something like call TO_CHAR with an appropriate 24 hour format mask:

SELECT
    TO_CHAR(TO_TIMESTAMP ('08-FEB-19 18.41.41.000000', 'DD-Mon-RR HH24.MI.SS.FF'),
        'DD-Mon-RR HH24.MI.SS.FF') AS ts
FROM dual;

08-Feb-19 18.41.41.000000000

演示

如果您想转换带有 12 小时时间和 AM/PM 组件的时间戳字符串,我们可以尝试:

If you wanted to convert a timestamp string with 12 hour time and an AM/PM component, we can try:

SELECT
    TO_CHAR(
        TO_TIMESTAMP ('08-FEB-19 06.41.41.000000 PM', 'DD-Mon-RR HH.MI.SS.FF PM'),
        'DD-Mon-RR HH24.MI.SS.FF')
FROM dual;

这篇关于如何将“2016-07-01 01:12:22 PM"转换为“2016-07-01 13:12:22"小时格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Query with t(n) and multiple cross joins(使用 t(n) 和多个交叉连接进行查询)
Unpacking a binary string with TSQL(使用 TSQL 解包二进制字符串)
Max rows in SQL table where PK is INT 32 when seed starts at max negative value?(当种子以最大负值开始时,SQL 表中的最大行数其中 PK 为 INT 32?)
Inner Join and Group By in SQL with out an aggregate function.(SQL 中的内部连接和分组依据,没有聚合函数.)
Add a default constraint to an existing field with values(向具有值的现有字段添加默认约束)
SQL remove from running total(SQL 从运行总数中删除)