1. 如何將系統時間轉換成數值型態日期和時間?
為了顯示(介面)、計算或儲存(到Table),常常需要將系統時間轉換為數值型態的變數,可以參考以下的RPG程式:
Convert system time to decimal variables.
* Return the variable values of RTNDATE & RTNTIME. * ---------------------------------------------------------------- C TIME SYSTIME 14 0 C* the SYSTIME will be HHmmssMMddyyyy. C MOVE SYSTIME TMPDATE 8 C MOVEL *BLANKS SAVDATE 8 C EVAL SAVDTE = %SUBST(TMPDATE:5:4)+ C %SUBST(TMPDATE:1:4) C MOVE SAVDATE RTNDATE 8 0 C TIME RTNTIME 6 02. 如何擷取自己時區的時間和日期?
可以根據系統時間來計算時區。比較好的方式是將系統時間先轉換成GMT時間(格林威治時間)再轉換成你要的國家(或時區)的時間,以方便各時區的人使用此程式,範例程式如下:
* To retrieve date & time (decimal) of specific Nation/Time zone. * Input Parameter: INPGAPD (the gap days between GMT and Nation/Time). * Output Parameter: RTNDATE, RTNTIME (decimal, date & time). * ----------------------------------------------------------------- D SYSTIME S Z D GMTTIME S Z D NATTIME S Z D DS D TMPYER 1 4 0 D TMPMTH 6 7 0 D TMPDAY 9 10 0 D TMPHOU 12 13 0 D TMPMIN 15 16 0 D TMPSEC 18 19 0 D TMPTIME 1 26 * ---------------------------------------------------------------- C* DIFGAPD : the gap days between System and GMT C* INPGAPD : the gap days between GMT and Nation/Time C C TIME SYSTIME C* SYSTIME format like '2018-01-29-10.39.34.144000' C C SYSTIME SUBDUR DIFGAPD:*H GMTTIME C GMTTIME ADDDUR INPGAPD:*H NATTIME C* C MOVEL NATTIME TMPTIME C EVAL RTNDATE=TMPYER*10000+TMPMTH*100+TMPDAY C EVAL RTNTIME=TMPHOU*10000+TMPMIN*100+TMPSEC * ----------------------------------------------------------------
沒有留言:
張貼留言