GMT timestamp

25 pts.
Tags:
iSeries
RPG
RPG Program
XML document
I am creating an XML document using RPG and I need to output a timestamp in GMT format : YYYYMMDDThhmmssZ The date will need to end up looking like this: 20131003T210212.001Z. Can anyone tell me how to do that in an RPG program on the iSeries?  Thank you.

Software/Hardware used:
i-series
ASKED: October 4, 2013  2:58 PM
UPDATED: October 10, 2013  1:46 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 7  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    Are you needing 'current time' as UTC? Or is it any timestamp that you might encounter? -- Tom
    125,585 pointsBadges:
    report
  • DStaats

    it will be both.  I will need to take the system date and convert to the UTC and I will also need to take a ISO timestamp that is in the EST time zone and convert it to GMT in the format 20131003T210212.001Z -- Darlene

    25 pointsBadges:
    report
  • TomLiotta

    The date will need to end up looking like this: 20131003T210212.001Z.

    Since that doesn't appear to be a valid XML DateTime format, is there a reason you need it to look like that? Also, do you know why you need to first convert to UTC time (and add the "Z") instead of just appending your timezone offset?

    It can be done either way for both questions, but you might want to be very sure of your requirements.

    One final detail... What exactly is the ".001" supposed to be at the end? Is that supposed to indicate that milliseconds are needed?

    Tom

    125,585 pointsBadges:
    report
  • TomLiotta
    BTW, the basic formatting is nothing more than taking substrings and concatenating them together with "T" and "Z". The only unusual part for you might be converting random timestamps to UTC timestamps. -- Tom
    125,585 pointsBadges:
    report
  • DStaats

    the format is per the customer requirements.  Is UTC the same thing as GMT?

    I'm not sure what the .001Z is.  I was assuming it was part of the GMT format that the customer is requiring. I guess I'll need to go back to the customer with that question.

    Darlene

    25 pointsBadges:
    report
  • RegnadKcin57

    FWiW: A web search on the following two delimited tokens, yielded the following two links; each with some quoted text included afterward:

    http://stackoverflow.com/questions/9706688/what-does-the-z-mean-in-unix-timestamp-120314170138z
     "...
    'Z' stands for Zulu time, which is also GMT and UTC.

    From http://en.wikipedia.org/wiki/Coordinated_Universal_Time:

        The UTC time zone is sometimes denoted by the letter Z ..."
     
    http://en.wikipedia.org/wiki/ISO_8601
     "...
    Date and time (current at page generation)
    expressed according to ISO 8601:
     ...
    Combined date and time in UTC: 2013-09-29T10:40Z
     ..."
     
    95 pointsBadges:
    report
  • TomLiotta

    Any character timestamp value can be formatted to fit the definition that you show. You can simply take substrings of a timestamp for year, month, etc., and concatenate them together.Whether it's the result actually needed by your customer is up to them.

    Getting UTC timestamps takes a little work. Not much, but some.

    I don't have good RPG examples yet, but I had a bunch of ILE CL code that works pretty much the same way. I pasted parts together for a working example. If it's not clear, I can put the same things together in RPG. I'll post this now just to get an example you might compile and use to compare against IBM documentation. It should compile and run on any system V5R3 and above (maybe earlier, but I can't test). It could a little nicer at V5R4 and above, but it's not clear what OS version you're running.

    pgm
    
       dcl   &QTIME       *char    6
       dcl   &QDATE       *char    6
       dcl   &QDATETIME   *char   20
       dcl   &QTIMZON     *char   10
       dcl   &QUTCOFFSET  *char    5
    
    /*   For Convert Date & Time...                                     */
    
       dcl   &CDT_I_FORM  *char   10     value( '*CURRENT' )
       dcl   &CDT_I_VAR   *char   20
       dcl   &CDT_O_FORM  *char   10     value( '*YYMD' )
       dcl   &CDT_O_VAR   *char   20
       dcl   &CDT_I_TZ    *char   10     value( '*JOB' )
       dcl   &CDT_O_TZ    *char   10     value( '*UTC' )
       dcl   &CDT_O_TZi   *char  111     value( ' ' )
       dcl   &CDT_O_TZl   *int           value( 111 )
       dcl   &CDT_O_Pi    *char    1     value( '0' )
    
    /* And we'll want to specify an errcode receiver at some points...  */
    
       dcl   &ERRCODE     *char  116     value( x'00000074' )
       dcl   &ERRLEN      *int           value( 0 ) /* +
                    Will tell us how long any exception data +
                    is... */
    
    /* These are all for CEE* transformations...                        */
    
       dcl   &RtnDt       *int           value( 0 )
       dcl   &RtnVal1     *char   15
       dcl   &RtnVal2     *char   24
       dcl   &RtnVal      *char    8
    
       dcl   &PicStr      *char   24     value( 'YYYY-MM-DDTHH:MI:SS.999 ' )
    
    
    /* Grab basic date/time system values for reference...              */
    
       rtvsysval   QTIME      rtnvar( &QTIME       )
       rtvsysval   QDATE      rtnvar( &QDATE       )
       rtvsysval   QDATETIME  rtnvar( &QDATETIME   )
       rtvsysval   QTIMZON    rtnvar( &QTIMZON     )
       rtvsysval   QUTCOFFSET rtnvar( &QUTCOFFSET  )
    
    /* Test conversion of QTIME to *UTC representation...               */
    
       call        QWCCVTDT         ( +
                                      &CDT_I_FORM +
                                      &CDT_I_VAR  +
                                      &CDT_O_FORM +
                                      &CDT_O_VAR  +
                                      &ERRCODE    +
                                      &CDT_I_TZ   +
                                      &CDT_O_TZ   +
                                      &CDT_O_TZi  +
                                      &CDT_O_TZl  +
                                      &CDT_O_Pi   +
                                    )
    
       chgvar      &ERRLEN        %bin( &ERRCODE  5 4 )
    
    /* Direct retrieval of UTC date and date-time...                    */
    
       callprc      CEEUTC       ( +
                                   &RtnDT         +
                                   &RtnVal        +
                                   *omit          +
                                 )
    
    /* Convert FLOAT8 to a commonly used human-readable format...       */
    
       callprc      CEEDATM      ( +
                                   &RtnVal        +
                                   'Mmm ZD HH:MI:SS' +
                                   &RtnVal1       +
                                   *omit          +
                                 )
    
    /* Convert FLOAT8 to XML dateTime format...                         */
    
       callprc      CEEDATM      ( +
                                   &RtnVal        +
                                   &PicStr        +
                                   &RtnVal2       +
                                   *omit          +
                                 )
       chgvar      &RtnVal2      ( &RtnVal2 *tcat 'Z' )
    
    dmpclpgm
    
       return
    
    endpgm

    It starts by grabbing various date/time system values. It doesn't use them for anything. It's just to have them in the final dump for comparisons.

    It then calls the Convert Date/Time API. It uses an input format of *CURRENT in order to use a full timestamp. Output format is *YYMD to ensure a full 4-digit year. It specifies *JOB for the input timezone, but uses *UTC for output timezone.

    The resulting output variable, &CDT_O_VAR, receives the timestamp converted to UTC. As coded, it uses the current system timestamp; but you can use any valid timestamp for input as long as you specify the correct input format.

    That API might be the only one you need, but I included a couple additional examples.

    The CEEUTC API returns current date and date/time values in an internal format. Those values are each passed into the CEEDATM API to show how values might be formatted using "picture strings". The first call to CEEDATM returns a form often seen in Unix systems. It's not useful to you except as a possible additional example to show what the API does.

    The second call to CEEDATM returns almost a precise XML dateTime value. If the trailing "Z" wasn't a special picture-string character, it wouldn't have to be added at the end.

    The picture-string that's used in that last example includes dashes and colons. Those could be removed if they're really not needed.

    See if any of that makes sense. If I get enough spare time, I'll see how much I can get coded in RPG.

    Tom

    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following