Convert a UTC time to GMT or BST

5 pts.
Tags:
AS/400
RPGLE
How do I convert a UTC time to a UK time (GMT or BST) on the AS/400 using RPGLE? The time may be in the past.
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

here is the source for a service program to convert back and forth between a UTC and a (local timezone) IBMi RPG Timestamp.

     h nomain option(*srcstmt:*nodebugio)

      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
      * Exported Procedure Prototypes
      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     d Unix2Rpg        pr              z
     d  pUnixTS                      10u 0 const

     d Rpg2Unix        pr            10u 0
     d  pRpgTS                         z   const

      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
      * Internal Procedure Prototypes
      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     d ceeutco         pr
     d  pHours                       10i 0
     d  pMins                        10i 0
     d  pSecs                         8f
     d  pFC                          12a   options(*omit)

      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
      * Global Variables and Constants
      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     d epoch           c                   const(z'1970-01-01-00.00.00')
     d offset          s             10i 0 inz(-1)
     d hours           s             10i 0
     d mins            s             10i 0
     d secs            s              8f

      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
      * Unix2Rpg():  Convert Unix timestamp -> RPG timestamp
      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     p Unix2Rpg        b                   export
     d Unix2Rpg        pi              z
     d  pUnixTS                      10u 0 const
      /free
         if (offset = -1);
            ceeutco(hours:mins:secs:*omit);
            offset = secs;
         endif;
         return epoch + %seconds(pUnixTS) + %seconds(offset);
      /end-free
     p Unix2Rpg        e

      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
      * Rpg2Unix(): Convert RPG timestamp -> Unix timestamp
      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     p Rpg2Unix        b                   export
     d Rpg2Unix        pi            10u 0
     d  pRpgTS                         z   const
      /free
         if (offset = -1);
            ceeutco(hours:mins:secs:*omit);
            offset = secs;
         endif;
         return %diff(pRpgTS:epoch + %seconds(offset):*seconds);
      /end-free
     p Rpg2Unix        e

Discuss This Question: 2  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.
  • aceofdelts
    I thought UTC time was GMT
    2,550 pointsBadges:
    report
  • ToddN2000
    Sounds like a homework question. Are you trying to convert data from another source?
    136,500 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.

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

Following

Share this item with your network: