Converting timestamps

Clovertech Forums Read Only Archives Cloverleaf Tcl Library Converting timestamps

  • Creator
    Topic
  • #54639
    Michael Hertel
    Participant

      I have a vendor sending eastern time zone timestamps.

      I am in the pacific time zone.

      I asked them to add time zone precision to the stamp so I could do the math.

      Thinking this would be easy using clock scan.

      They are sending:

      20150410134704-0400 (Eastern time zone)

      I want to convert it to:

      20150410104704-0800 (Pacific time zone)

      I can’t seem to figure out how to code this in tcl.

      And actually, I don’t need the precision on the resulting pacific time stamp.

    Viewing 1 reply thread
    • Author
      Replies
      • #82365
        Charlie Bursell
        Participant

          You can do some date math but the new, improved clock command in Tcl 8.5 is better – comes with Cloverleaf 6+

          set indate 20150410134704-0400

          # Split out the date and offset

          lassign [split $indate -] dttm offset’

          # Make the date scannable by making date and time a list

          regsub — {(d{8})(d*$)} $dttm {1 =2} scandt

          # Let clock command do the convert

          set newdt [clock format

             [clock scan $ff -timezone :America/New_York]

             -format %Y%m%d%H%M%S -timezone :America/Los_Angeles]

          ====> NEWDATE: 20150410104704

          There are other ways but the clock command will take care of things like leap year, etc.

          echo NEWDATE: $newdt

        • #82366
          Michael Hertel
          Participant

            Thank you Charlie!

        Viewing 1 reply thread
        • The forum ‘Tcl Library’ is closed to new topics and replies.