as400 RPGLE以UNIX纪元格式获取UTC时间

问题描述 投票:1回答:2

仍在学习RPG / as400。我需要以UNIX纪元格式获取UTC的当前日期和时间。我没有太多运气寻找如何将标准dd / mm / yyyy hh:mm:ss转换为unix格式。是否可以从as400提取UNIX时间戳?

ibm-midrange rpgle
2个回答
1
投票

我真的很需要这个...

但是从ILE RPG中,您可以调用C函数...这似乎是您想要的...mktime() — Convert Local Time

如果您不熟悉从ILE RPG调用C函数,这是一篇不错的文章,甚至涵盖了mktime()。Supplementing RPG's Native Date/Time Support

[请注意,所需的原型和数据结构定义可在ILERPE源文件(QRPGLESRC)成员“ time”中的“ System Includes”库QSYSINC中找到...>

 /include QSYSINC/QRPGSRC,TIME
 dcl-s  myUnixTime like(time_t)
 dcl-ds myTimeDs   likeds(struct_tm)

 //note: fill in myTimeDS here
 myTimeDs.tm_min = 0;
 // and so on...
 myUnixTime = mktime(myTimeDs);

如果您的系统上没有QSYSINC库,请询问管理员以安装OS的option 13 - System Openness Includes(LICPGM 5770-ss1)

最后,您可以使用以下摘录。。

 D time_t                        10I 0 template
 D struct_tm...
 D                 DS                  QUALIFIED ALIGN
 D                                     TEMPLATE
  //  int tm_sec;             /* seconds after the minute (0-61)        */
  //  int tm_min;             /* minutes after the hour (0-59)          */
  //  int tm_hour;            /* hours since midnight (0-23)            */
  //  int tm_mday;            /* day of the month (1-31)                */
  //  int tm_mon;             /* months since January (0-11)            */
  //  int tm_year;            /* years since 1900                       */
  //  int tm_wday;            /* days since Sunday (0-6)                */
  //  int tm_yday;            /* days since January 1 (0-365)           */
  //  int tm_isdst;           /* Daylight Saving Time flag              */
 D tm_sec                        10I 0
 D tm_min                        10I 0
 D tm_hour                       10I 0
 D tm_mday                       10I 0
 D tm_mon                        10I 0
 D tm_year                       10I 0
 D tm_wday                       10I 0
 D tm_yday                       10I 0
 D tm_isdst                      10I 0
 D mktime          PR                  LIKE(time_t)
 D                                     EXTPROC('mktime')
 D  time                               LIKEDS(struct_tm)

0
投票

当您与外界交流时,总是有这样的需求,例如JWT(检查令牌是否已过期)。

© www.soinside.com 2019 - 2024. All rights reserved.