且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将24小时的时间转换为12小时加AM / PM指示Oracle SQL

更新时间:2022-12-17 19:04:57

对于24小时的时间,你需要使用 HH24 而不是 HH

For the 24-hour time, you need to use HH24 instead of HH.

对于12小时的时间, AM / PM指标写为 AM (如果您想要结果中的期间)或 AM (如果你't)。例如:

For the 12-hour time, the AM/PM indicator is written as A.M. (if you want periods in the result) or AM (if you don't). For example:

SELECT invoice_date,
       TO_CHAR(invoice_date, 'DD-MM-YYYY HH24:MI:SS') "Date 24Hr",
       TO_CHAR(invoice_date, 'DD-MM-YYYY HH:MI:SS AM') "Date 12Hr"
  FROM invoices
;

有关格式模型的更多信息,可以使用 TO_CHAR ,请参阅 http://docs.oracle.com /cd/E16655_01/server.121/e17750/ch4datetime.htm#NLSPG004

For more information on the format models you can use with TO_CHAR on a date, see http://docs.oracle.com/cd/E16655_01/server.121/e17750/ch4datetime.htm#NLSPG004.