問題描述
誰能幫助我如何在 PL/SQL 中將 2016-07-01 01:12:22 PM
轉(zhuǎn)換為 2016-07-01 13:12:22
?我使用了以下但沒有運(yùn)氣.
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
我預(yù)計(jì):08-FEB-19 18.41.41.000000
I expect: 08-FEB-19 18.41.41.000000
我收到以下錯(cuò)誤:
ORA-01830:日期格式圖片在轉(zhuǎn)換整個(gè)輸入字符串之前結(jié)束
ORA-01830: date format picture ends before converting the entire input string
推薦答案
您當(dāng)前的時(shí)間戳沒有任何意義,因?yàn)樗付ǖ臅r(shí)間為 18
小時(shí),即下午 6 點(diǎn),但隨后它也指定了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 內(nèi)部確實(shí)沒有 12 或 24 小時(shí)格式時(shí)間戳之類的東西.相反,如果您想以 24 小時(shí)格式查看您的 Oracle 時(shí)間戳,您可以使用適當(dāng)?shù)?24 小時(shí)格式掩碼調(diào)用 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
演示
如果您想轉(zhuǎn)換帶有 12 小時(shí)時(shí)間和 AM/PM 組件的時(shí)間戳字符串,我們可以嘗試:
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;
這篇關(guān)于如何將“2016-07-01 01:12:22 PM"轉(zhuǎn)換為“2016-07-01 13:12:22"小時(shí)格式?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!