ILE RPG - 如何将时间值转换为数值?

时间:2016-09-06 14:24:46

标签: ibm-midrange rpgle

请考虑以下代码:

D#TIME1           S               T                                             
D#numeric1        S              6  0                                           
D#numeric2        S              6  0                                           
D                                                                               
C                   TIME                    #numeric1                           
C                   eval      #TIME1 = %TIME(#numeric1:*HMS)                    
C                                                                               
C*                  This does not work:                                             
C                   eval      #numeric2 = %int(TIME1)                           
C*                  Errormessage: The expression contains a operator, which is not defined
C                                                                               
C                   MOVE      *ON           *INLR            

有人可以告诉我,如何将* HMS时间值(例如' 07:02:22')转换为6 0数值。我需要这个来比较两个时间戳。

2 个答案:

答案 0 :(得分:5)

C                   eval      #numeric2 = %dec(TIME1: *hms)  

应该做的伎俩。

答案 1 :(得分:1)

您可以在TIME操作码的结果字段中使用时间字段。或者,要获取当前时间,您可以使用%TIME()而不使用参数。

D#TIME1           S               T
D#curTime         S               T

C                   TIME                    #curTime 
C                   IF        #TIME1 >= #curTime

或者,如果您以后不需要当前时间,请直接在比较中使用%TIME():

C                   IF        #TIME1 >= %time()
相关问题