GMT Time Conversion

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf GMT Time Conversion

  • Creator
    Topic
  • #49369
    Robbie Parker
    Participant

      Any ‘simple’ ideas on how to convert GMT time to local time?

    Viewing 2 reply threads
    • Author
      Replies
      • #61669
        Jim Kosloskey
        Participant

          Robbie,

          First let me say I have never done this – never had the need – so I don’t have any ‘tricks’.

          You are in the US Eastern Time Zone. If I recall correctly that is +8 hours relative to GMT (you can check this on the Web).

          Hopefully your source time is in 24 hour (sometimes called ‘military’) time format. If it is not, you probably will want to convert it.

          Then add 8 hours (or whatever you discover your offset is) to the hours portion of the GMT time you are given. If your result exceeds 24, subtract 24 from the hours – and if you also need to handle date, increment your date by one day (remember to adjust if flowing over a month or year).

          Jim Kosloskey

          email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

        • #61670
          Rob Abbott
          Keymaster

            Use the Tcl ‘clock’ command for any date/time math.

            clock scan – convert time/date formats into epoch seconds

            Do any math on the epoch (e.g. subtract (60 * 60 * 5) from the epoch in GMT)

            clock format – convert epoch seconds back into time/date formats

            tclhelp or ‘help clock’ will give you all the details.

            Jim – I think EST is GMT-5 😉

            Rob Abbott
            Cloverleaf Emeritus

          • #61671
            Charlie Bursell
            Participant

              Even simplier.  The clock command is your friend  ðŸ™‚

              You must have a date/time string that is scanable.  The clock scan command expects the date/time to be a list where the date is the first element and the time, if present, is the second element.

              Given a GMT date/time in the format:

                              set datetime 20070626100505

              An easy way to make it scanable is with regsub.  This command will put a space between date and time, if there, else it will leave it as is if no time.

                             regsub — {(d{8})(d*)} $datetime {1 2} datetime

              Then simply use the clock command to format to local time.  Your OS time zone environment will be used for the difference between local and GMT

              set local [clock format [clock scan $time -gmt 1]

                                                      -format %Y%m%d%H%M%S]

              Assume you are on Central Time

              echo $local

              =>  20070626050505

          Viewing 2 reply threads
          • The forum ‘Cloverleaf’ is closed to new topics and replies.