CEESECS: 将时间戳记转换为秒

CEESECS 将表示时间戳记的字符串转换为 Lilian 秒数 (自 1582 年 10 月 00:00:00 以来的秒数)。 此服务使执行时间算术 (例如,计算两个时间戳记之间的耗用时间) 更容易。

CALL CEESECS 语法

读取语法图跳过可视语法图CALL"CEESECS"USING输入时间戳记,picture_string,输出秒数,FC.
input_timestamp (输入)
半字长度前缀字符串,表示格式与 picture_string指定的格式匹配的日期或时间戳记。

字符串必须包含 5 到 80 个图片字符 (含)。 input_timestamp 可以包含前导或尾部空格。 解析以第一个非空白字符开始 (除非图片字符串本身包含前导空格; 在本例中, CEESECS 在解析开始之前正好跳过那么多位置)。

解析有效日期后 (由您在 picture_string中指定的日期的格式确定) , CEESECS 将忽略所有剩余字符。 有效日期范围从 1582 年 10 月 15 日至 9999 年 12 月 31 日。 必须指定完整日期。 有效时间范围从 00:00:00.000 到 23:59:59.999。

如果省略了任何部分或全部时间值,那么将用零替换其余值。 例如:


1992-05-17-19:02 is equivalent to 1992-05-17-19:02:00
1992-05-17       is equivalent to 1992-05-17-00:00:00
picture_string (输入)
半字长度前缀字符串,指示 input_timestamp中指定的日期或时间戳记值的格式。

picture_string 中的每个字符表示 input_timestamp中的一个字符。 例如,如果指定 MMDDYY HH.MI.SS 作为 picture_string, CEESECS 在 1988 年 6 月 2 日下午 3:35:02 读取 060288 15.35.02 的 input_char_date 。 如果在图片字符串中出现斜杠 (/) 之类的定界符,那么可以省略前导零。 例如,对 CEESECS 的以下调用都将相同的值分配给数据项 secs:


CALL CEESECS USING '92/06/03 15.35.03',
                   'YY/MM/DD HH.MI.SS', secs, fc.
CALL CEESECS USING '92/6/3 15.35.03',
                   'YY/MM/DD HH.MI.SS', secs, fc.
CALL CEESECS USING '92/6/3 3.35.03 PM',
                   'YY/MM/DD HH.MI.SS AP', secs, fc.
CALL CEESECS USING '92.155 3.35.03 pm',
                   'YY.DDD   HH.MI.SS AP', secs, fc.

如果 picture_string 包含日语 Era 符号 <JJJJ>,那么 input_timestamp 中的 YY 位置表示日语 Era 中的年号。 例如, 1988 年等于昭和时代的日本第 63 年。

output_seconds (输出)
64 位长浮点数,表示自 1582 年 10 月 14 日 00:00:00 以来的秒数,不计入闰秒。 例如, 1582 年 10 月 15 日的 00:00:01 是 Lilian 格式的第二个 86,401 (24 * 60 * 60 + 01)。 19:00:01.12 1988 年 5 月 16 日是第二个 12,799,191 ,601.12。

表示的最大值为 23:59:59.999 (在 9999 年 12 月 31 日) ,即 Lilian 格式的第二个 265,621,679 和999.999 。

64 位长浮点值可以准确表示大约 16 位有效十进制数字,而不会丢失精度。 因此,精确到最接近的毫秒 (15 位小数)。

如果 input_timestamp 不包含有效的日期或时间戳记,那么 output_seconds 将设置为 0 ,并且 CEESECS 将终止并带有 non-CEE000 符号反馈代码。

output_seconds上轻松执行耗用时间计算,因为它表示耗用时间。 闰年和年终异常不影响计算。

fc (输出)
指示此服务结果的 12 字节反馈代码 (可选)。
表 1. CEESECS 符号条件
符号反馈代码 严重性 消息号 消息文本
CEE000 0 -- 服务已成功完成。
CEE2EB 3 2507 传递到 CEEDAYS 或 CEESECS 的数据不足。 未计算 Lilian 值。
CEE2EC 3 2508 传递给 CEEDAYS 或 CEESECS 的日期值无效。
CEE2ED 3 2509 无法识别传递给 CEEDAYS 或 CEESECS 的时代。
CEE2EE 3 2510 无法识别对 CEEISEC 或 CEESECS 的调用中的小时值。
CEE2EH 3 2513 在 CEEISEC , CEEDAYS 或 CEESECS 调用中传递的输入日期不在受支持的范围内。
CEE2EK 3 2516 未识别 CEEISEC 调用中的分钟值。
CEE2EL 3 2517 未识别 CEEISEC 调用中的月份值。
CEE2EM 3 2518 在对日期/时间服务的调用中指定了无效的图片字符串。
CEE2EN 3 2519 未识别 CEEISEC 调用中的秒数值。
CEE2EP 3 2521 传给 CEEDAYS 或 CEESECS 的 <JJJJ>、<CCCCC> 或 <CCCCCCCC> 年代内年份值为零。
CEE2ET 3 2525 CEESECS 在数字字段中检测到非数字数据,或者时间戳记字符串与图片字符串不匹配。

使用说明

  • CEESECS 的逆函数是 CEEDATM ,它将 output_seconds 转换为字符格式。
  • 缺省情况下,两位数的年份位于系统日期之前 80 年开始的 100 年范围内。 因此,在 2010 年,所有两位数的年份都表示 1930 年到 2029 年之间的日期,包括 1930 年和 2029 年。 您可以使用可调用服务 CEESCEN 来更改此范围。

示例


************************************************
**                                            **
** Function: Call CEESECS to convert          **
**           time stamp to number of seconds  **
**                                            **
** In this example, calls are made to CEESECS **
** to convert two time stamps to the number   **
** of seconds since 00:00:00 14 October 1582. **
** The Lilian seconds for the earlier         **
** time stamp are then subtracted from the    **
** Lilian seconds for the later time stamp    **
** to determine the number of between the     **
** two.  This result is displayed.            **
**                                            **
************************************************
 IDENTIFICATION DIVISION.
 PROGRAM-ID. CBLSECS.

 DATA DIVISION.
 WORKING-STORAGE SECTION.
 01  SECOND1                 COMP-2.
 01  SECOND2                 COMP-2.
 01  TIMESTP.
     02  Vstring-length      PIC S9(4) BINARY.
     02  Vstring-text.
         03  Vstring-char        PIC X,
                     OCCURS 0 TO 256 TIMES
                     DEPENDING ON Vstring-length
                        of TIMESTP.
 01  TIMESTP2.
     02  Vstring-length      PIC S9(4) BINARY.
     02  Vstring-text.
         03  Vstring-char        PIC X,
                     OCCURS 0 TO 256 TIMES
                     DEPENDING ON Vstring-length
                        of TIMESTP2.
 01  PICSTR.
     02  Vstring-length      PIC S9(4) BINARY.
     02  Vstring-text.
         03  Vstring-char        PIC X,
                     OCCURS 0 TO 256 TIMES
                     DEPENDING ON Vstring-length
                        of PICSTR.
 01  FC.
     02  Condition-Token-Value.
     COPY  CEEIGZCT.
         03  Case-1-Condition-ID.
             04  Severity    PIC S9(4) COMP.
             04  Msg-No      PIC S9(4) COMP.
         03  Case-2-Condition-ID
                   REDEFINES Case-1-Condition-ID.
             04  Class-Code  PIC S9(4) COMP.
             04  Cause-Code  PIC S9(4) COMP.
         03  Case-Sev-Ctl    PIC X.
         03  Facility-ID     PIC XXX.
     02  I-S-Info            PIC S9(9) COMP.
 PROCEDURE DIVISION.

 PARA-SECS1.
************************************************
** Specify first time stamp and a picture string
**     describing the format of the time stamp
**     as input to CEESECS
************************************************
     MOVE 25 TO Vstring-length of TIMESTP.
     MOVE '1969-05-07 12:01:00.000'
             TO Vstring-text of TIMESTP.
     MOVE 25 TO Vstring-length of PICSTR.
     MOVE 'YYYY-MM-DD HH:MI:SS.999'
             TO Vstring-text of PICSTR.

************************************************
** Call CEESECS to convert the first time stamp
** to Lilian seconds
************************************************
     CALL 'CEESECS' USING TIMESTP, PICSTR,
                          SECOND1, FC.
     IF NOT CEE000 of FC  THEN
         DISPLAY 'CEESECS failed with msg '
             Msg-No of FC UPON CONSOLE
         STOP RUN
     END-IF.

 PARA-SECS2.
************************************************
** Specify second time stamp and a picture string
**     describing the format of the time stamp as
**     input to CEESECS.
************************************************
     MOVE 25 TO Vstring-length of TIMESTP2.
     MOVE '2004-01-01 00:00:01.000'
             TO Vstring-text of TIMESTP2.
     MOVE 25 TO Vstring-length of PICSTR.
     MOVE 'YYYY-MM-DD HH:MI:SS.999'
             TO Vstring-text of PICSTR.

************************************************
** Call CEESECS to convert the second time stamp
**     to Lilian seconds
************************************************
     CALL 'CEESECS' USING TIMESTP2, PICSTR,
                          SECOND2, FC.
     IF NOT CEE000 of FC  THEN
         DISPLAY 'CEESECS failed with msg '
             Msg-No of FC UPON CONSOLE
         STOP RUN
     END-IF.

 PARA-SECS2.
************************************************
** Subtract SECOND2 from SECOND1 to determine the
**     number of seconds between the two time stamps
************************************************
     SUBTRACT SECOND1 FROM SECOND2.
     DISPLAY 'The number of seconds between '
         Vstring-text OF TIMESTP ' and '
         Vstring-text OF TIMESTP2 ' is: ' SECOND2.

     GOBACK.

示例:日期和时间图片字符串

相关参考资料
图片字符术语和字符串