rpgle - RPG 4:将有符号整数转换为日期和时间
问题描述
我需要将时间戳(在 Signed Int 中)转换为日期和时间。我该怎么做?
主意:
D stampint 10I 0 //- value: '1455554435' - input parm
D Varprint 10A
D Varprint2 8A 0
/free
Varprint = %char(%date( (<cast to timestamp> stampint) :*MDY));
Varprint2 = %char(%time( (<cast to timestamp> stampint) :*HMS));
dsply Varprint;
dsply Varprint;
inlr = *on;
return ;
/End-free
Objective result:
DSPLY 02/15/2016
DSPLY 16:40:35
谢谢。
更新:对不起,我提出的问题太快了,以至于我没有正确报告。
目标是能够报告日期和时间,而不管变量的类型如何。Var1 可以是 * CHAR 或数字(打包)。Varprint 和 Varprint2 是一个例子,但我想知道如何从类型 I 转换为类型 Z。
我曾尝试使用:
D timestmp Z inz('1970-01-01-00.00.00.000000')
D result Z inz('0001-01-01-00.00.00.000000')
... code..
/free
result = timestmp + %seconds(stampint);
dsply result;
/end-free
但结果是错误的。
我也试过:
Varprint = %char(%date( %editc(stampint:'Z') :*MDY));
但是它给出了编译错误: *RNF7416- 左右手边的类型不进行 EVAL 操作。
解决方案
您需要使用 %timestamp(),除了 10 位整数对于实际时间戳来说不够大......日期为 6 位,时间为 6 位(包括秒)
最好的办法是使用%editc(sampint:'X')
前导零转换为字符串,然后 %subst() 打破日期,我假设一段时间内只有 'HH:MI' ......
如果要转换为实际时间类型,则需要连接 ':00' 秒才能使用 %time();
推荐阅读
- php - 使用事件名而不是 ID 删除记录
- python - 把函数放在后台
- javascript - d3.js 如何仅将那些节点动态添加到可折叠树中,从数据表中选择
- reactjs - 让图标出现在 React - 三元表达式
- c# - 如何用文本填充和显示数组中的空元素
- python - 将数据框转换为包含字典列表的字典
- hadoop - 在没有 mapred-site.xml 的情况下设置 hadoop mapreduce 大小
- c# - 如何在 Winform 应用程序中使用 C# 中的 Syncfusion 的 colorPickerUIAdv1 控件获取 rgb 格式的选定颜色值
- javascript - NodeJS - setTimeout 完成后运行函数
- elasticsearch - 在弹性搜索中是否可以使用多组应该