Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
This is a stand-alone program that displays the current local time and the GMT time. In addition it shows you the UTC Offset.
NOTE: If you CEEUTCO is returning the incorrect UTC Offset or your Apache Log file is recording the wrong offset, read this article on how to fix this problem on your system.
To compile this program, you'll need to have the free RPG Open service program installed on your system or an equivalent service program that includes a JOBLOG subprocedure. RPG xTools is one, as is the code that comes with RPG TnT book.
H MAIN(DSPGMT) BNDDIR('RPGOPEN/RPGOPEN') H DFTACTGRP(*NO) OPTION(*SRCSTMT) /include RPGOPEN/qcpysrc,joblog /if NOT DEFINED(CEE_DATE_API) /DEFINE CEE_DATE_API D ceeutc PR D output_lil 10I 0 D output_secs 8F D feedback 12A OPTIONS(*OMIT) D ceeutco PR D output_hrs 10I 0 D output_mins 10I 0 D output_secs 8F D feedback 12A OPTIONS(*OMIT) D ceedatm PR OPDESC D lilianSeconds 8F Const D dateFmtPic 26A Const OPTIONS(*varsize) D output_TmStmp 26A OPTIONS(*varsize) D feedback 12A OPTIONS(*OMIT) D ceeFMDA PR OPDESC D countryCode 2A Const D rtnCountryCode 32A OPTIONS(*VARSIZE) D feedback 12A OPTIONS(*OMIT) /endif D QUSRJOBI PR EXTPGM('QUSRJOBI') D rtnData 6000A OPTIONS(*VARSIZE) D sizeRtnData 10I 0 Const D fmtName 8A Const D jobName 26A Const D InternalJobID 16A Const D JobI_TZ_T DS Qualified D tzName 10A D reserved1 1A D dstActive 1A D UTC_Offset 10I 0 D fullname 50A D abbrName 10A D tz_MsgID 7A D tz_MsgFile 10A D tz_MsgLib 10A D reserved2 1A D UTC_Year_Offset... D 10I 0 D JobTimeZone_T DS Qualified Inz D bytesReturned 10I 0 D bytesAvail 10I 0 D stuff_we_do_not_want... D 316A D offset_TZ 10I 0 D length_TZ 10I 0 D timeZoneArea 200A D dspGMT PR extpgm('DSPGMT') P dspGMT B D dspGMT PI D lilian S 10I 0 D hrs S 10I 0 D mins S 10I 0 D utcSecs S 8F D secs S 8F D szChar S 26A D dst S 32A Varying D relation S 1A D utcCoord S 5A D utcOffset S T Inz D locTime S Z D gmTime S Z D myJobTZ DS LikeDS(JobTimeZone_T) Inz(*LIKEDS) D tz_Info DS LikeDS(jobI_TZ_T) based(pTZ) D jobName S 26A Inz('*') D JOBI0600 C Const('JOBI0600') D JOBID S 16A Inz(*BLANKS) /free ceeutc(lilian : secs : *omit); // Get GMT ceeutco(hrs : mins : utcSecs : *omit); // Return UTC Offset ceedatm(secs : 'YYYY-MM-DD-HH.MI.SS.999': szChar : *omit); gmTime = %timestamp(szChar); locTime = gmTime + %seconds(%int(utcSecs)); utcOffset -= %hours(hrs); utcOffset -= %minutes(mins); if (hrs < 0); relation = '-'; else; relation = '+'; endif; QUSRJOBI(myJobTZ :%size(myJobTZ) : jobi0600 : jobName : jobID); pTZ = %addr(myJobTZ) + myJobTZ.offset_TZ; if (tz_Info.dstActive=*ON); DST = 'DST Active'; else; DST = 'Standard Time Active'; endif; utcCoord = %char(utcOffset:*HMS); joblog(' +--Date--+ +---Time---+'); joblog(' | | | |'); joblog('Geenwich Mean Time: %s': %char(gmTime)); joblog('Local time . . . : %s': %char(locTime)); joblog('UTC-Offset . . . : %s%s': relation:utcCoord); joblog('DST Status . . . : %s': dst); return; /end-free P dspGMT E