IBM ILE RPG - 如何存储大于 24 小时的时间值

IBM ILE RPG - How to store time values greater than 24h

如何在 TIME 变量中存储时间值(例如:33h 24m 02s),因为 *HIVAL - 最大值 - 是 24h 00m 00s。

有时将其存储在数据结构 (DS) 中(当值小于 10 时)例如:33:24:03 该值显示为 33.24.3,因为该字段不会自动用零填充

你已经回答了你自己的问题,限制是 24 小时。

我不确定你想要完成什么,但我建议你使用 %diff() Built-in Function (BIF) to get the difference between the two time/date/timestamp values and store it in an integer. And then to manipulate another time/timestamp field you could use the %seconds() BIF。

例如:

       ctl-opt dftactgrp(*no) actgrp(*new);
       ctl-opt timfmt(*iso);

       dcl-s time1 time inz(t'09.25.00');
       dcl-s time2 time inz(t'10.00.00');
       dcl-s time3 time;
       dcl-s SecondsDiff int(10);
       dcl-s result char(1);

       SecondsDiff = %diff(time2: time1: *seconds);

       time3 = %time() + %seconds(SecondsDiff);

       dsply ('In 35 minutes it will be: ' + %char(time3)) '*EXT' result;

       *inlr = *on; 

这是一个非常简单的例子,如果你能给我更多关于你想要完成的事情的信息,我可以给出一个更具体的例子。

编辑

这是一个示例程序,可以满足您的要求:

       ctl-opt dftactgrp(*no) actgrp(*new);

       dcl-s SecondsChar char(20);
       dcl-s Result varchar(32);
       dcl-s WaitAnyKey char(1);

       dsply 'Enter an amount of seconds: ' '*EXT' SecondsChar;

       Result = SecondsToDisplay(%int(SecondsChar));

       dsply Result '*EXT' WaitAnyKey;
       *inlr = *on;

       dcl-proc SecondsToDisplay;
         dcl-pi *n varchar(32);
           Seconds int(10) value;
         end-pi;

         dcl-s Result varchar(32) inz('');
         dcl-s CurrentValue int(10);

       Seconds = %abs(Seconds);

       //Get the days
       CurrentValue = Seconds / 86400;
       if (CurrentValue > 0);
         Result = %char(CurrentValue) + 'd ';
         Seconds = %rem(Seconds: 86400);
       endif;

       //Get the hours
       CurrentValue = Seconds / 3600;
       if (CurrentValue > 0 OR Result <> '');
         Result += %char(CurrentValue) + 'h ';
         Seconds = %rem(Seconds: 3600);
       endif;

       //Get the minutes
       CurrentValue = Seconds / 60;
       if (CurrentValue > 0 OR Result <> '');
         Result += %char(CurrentValue) + 'm ';
         Seconds = %rem(Seconds: 60);
       endif;

       //The seconds
       Result += %char(Seconds) + 's';


       return Result;

       end-proc; 

和一些示例输出:

DSPLY Enter an amount of seconds: 799240
DSPLY 9d 6h 0m 40s