且构网

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

将军事时间转换为标准时间误差

更新时间:2023-02-06 16:43:15

通过一系列强制转换,您可以执行以下操作:

Doing this through a series of casts, you could do something like:

SELECT CAST(CAST(CAST(CAST((1420 * 100 (FORMAT '99:99:99')) AS CHAR(8)) AS time ) AS TIME FORMAT 'HH:MIBT') AS CHAR(8))

可以使用一些数学运算来对它进行排序并在最后强制转换:

Or you could use some math to sort it out and cast at the end:

SELECT 
  1420 AS intTime,
  FLOOR(intTime/100) AS intHours,
  intTime - (intHours * 100) AS intMinutes,
  intHours * 60 + intMinutes AS totalIntMinutes,
  TIME '00:00:00' + (totalIntMinutes * INTERVAL '1' MINUTE) AS totalTime,
  CAST(CAST(totalTime AS TIME FORMAT 'HH:MIBT') AS CHAR(8)) AS char12HrTime

或者只是解析和数学事物:

Or just parse and math the thing:

SELECT 
  1420 AS intTime,
  Trim(CASE WHEN FLOOR(intTime/100) > 12 then FLOOR(intTime/100) - 12 ELSE FLOOR(intTime/100) END) || ':' || TRIM(intTime - (FLOOR(intTime/100) * 100))

可能还有其他几种方法

无论用哪种方式剪切,这都会有点难看,因为您将时间存储为时间类型。

Either way you cut it this is going to be a little ugly since you are storing time as something other than a time type.