ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Convert UTC time to Date/Time in RPG Free

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Convert UTC time to Date/Time in RPG Free

    I'm not sure why I'm having such a problem converting a UTC format date to a date/time I can read in an RPG program but I cannot get it to work. Anyone have a simple example? It should be easy I would think. API maybe.
    Thanks

  • #2
    What exactly is "UTC format"? And what does your code look like? It's probably a simple fix for whatever code that you have.
    Tom

    There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

    Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

    Comment


    • #3
      Its a unix type format. Like this number 1483697016347 converted to a date and time is 01/06/17 05:03:36 eastern time.

      Comment


      • #4
        I got it to work by taking the first 10 digits of the 13 digit UTC number and adding to 01/01/1970 and it worked. Not sure what the other 3 digits are used for. One way around it I guess

        Comment


        • #5
          AFAIK, UTC is for time zones and is roughly equivalent to GMT.

          Unix epoch time is the number of seconds since an arbitrary origin. I'm not sure where you're extra 3 digits come from. Could they be decimals (e.g. packed(13,3))?

          Comment


          • jtaylor___
            jtaylor___ commented
            Editing a comment
            That origin being the 1970-01-01 you mentioned.

        • #6
          Not sure what the extra digits are for. I'm asking the 3rd party to see what they say. And yes it is the 1970-01-01 date adding seconds too.

          Comment


          • #7
            Looks like api QWCCVTDT will do what you want:

            Comment


            • CaptainRon
              CaptainRon commented
              Editing a comment
              I thought that too but the incoming data it UTC. So the optional parm has UTC but the first input does not. I could not get that to work. So I just added the UTC to 1970/01/01. One line of code instead of coding an API etc.

          • #8
            Originally posted by Rocky View Post
            Looks like api QWCCVTDT will do what you want:
            Will it? I don't see that it accepts a seconds-only parm. Now it looks like it would do the time zone conversion from UTC to local (if required).

            Comment


            • CaptainRon
              CaptainRon commented
              Editing a comment
              agreed. I could not get it to work like I wanted too

          • #9
            If it's a Unix (or epoch) timestamp, it's the number of seconds since 1970-01-01, probably GMT (so no time zone offset).

            MyStamp = D'1970-01-01' + %Seconds(YourSeconds) ;

            Add (or subtract) %hours and %minutes offset if you need to.

            Comment


            • #10
              Originally posted by jtaylor___ View Post

              Will it? I don't see that it accepts a seconds-only parm. Now it looks like it would do the time zone conversion from UTC to local (if required).
              It appears so to me....

              Well - I thought the optional parameters might address your concern... but perhaps the following?

              gmtime64() function, gmtime64, time, library functions, tm structure, converting

              Comment


              • #11
                What you have here is not "UTC format", it is a Unix-style timestamp, which is a count of the number of seconds that have elapsed since the "epoch' (jan 1 1970). It is probably in the UTC time zone as well, as that is fairly standard with Unix time stamps.

                The solution is to:

                1) Add the number of seconds to Jan 1 1970. RPG's built-in timestamp math works nicely for this. This gives you a timestamp, but it is in the UTC timezone.

                2) If you want the result in the current frame of reference (i.e. current time zone and daylight savngs time) the CEEUTCO API can give you the number of seconds offset from UTC and you can simply add that to the timestamp as well.

                3) If you prefer the date in the date's frame of reference (i.e. show the daylight savings time offset if the date was during daylight savings time) then take the UTC timestemp from step 1 and convert the timezone with the QWCCVTDT API.

                I don't understand why someone would recommend using gmtime64, here, unless you plan to do this in C/C++.

                Comment

                Working...
                X