command for getting current time with milliseconds

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf command for getting current time with milliseconds

  • Creator
    Topic
  • #52013
    Hongle Sun
    Participant

      I am using [clock format [clock seconds] -format “%Y%M%d%H%M%S”] to retrieve current system date upto seconds.

      The output for the above statement is “201009291510129”, but I would like to know if there is a similar way to retrieve upto milliseconds in the above format. Thanks

    Viewing 5 reply threads
    • Author
      Replies
      • #72709
        David Barr
        Participant

          Why do you need to do this?

          You can use “clock clicks” to get a time counter in milliseconds, but this value doesn’t seem to be synchronized with “clock seconds”.  In other words, [expr [clock clicks -milliseconds]%1000] doesn’t go to zero at the time that [clock seconds] changes.

        • #72710
          Hongle Sun
          Participant

            Thanks David. I actully would like to use the system timestamp with millisecond  to be messsage_control id within ADT message.

          • #72711
            Jim Kosloskey
            Participant

              Hongle,

              What I do is to use the clock seconds plus a 3 character literal plus a counter. The counter breaks ties at the seconds level, the literal means I can have uniqueness accross systems as well as within a system (across sytems can be useful if the receiving system is getting messages from multiple sources (ADT, Orders, Results, etc.) and every message has to have a unique ID forever.

              The above mecahnism can assure such uniqueness and still stay within the 22 character limit of MSH-10.

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

            • #72712
              David Barr
              Participant

                Well, if you’re mostly concerned with uniqueness, you could use something like

                Code:

                clock format [clock seconds] -format “%Y%M%d%H%M%S[expr [clock clicks -milliseconds]%1000]”

                .

                Just be aware that the milliseconds portion of the time will probably guarantee uniqueness, but won’t always be sequential.  In other words, a message may come in the same second as another message, and it’s timestamp might have a lower value.

              • #72713
                Jim Kosloskey
                Participant

                  Dave,

                  I don’t think that will assure uniqueness since the value gene4rated by the clock clicks -milliseconds will have the same value within a given second. So if multiple messages are delviered per second they will all have the same ID.

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

                • #72714
                  David Barr
                  Participant

                    clock clicks -milliseconds gives you a counter that changes each millisecond, so if you call it twice within a second (but not within a millisecond) it will be unique.

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