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

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"小时格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)