3 Replies Latest reply on Jun 14, 2021 2:20 AM by Suvam Pani

    Convert Timestamp to UTC

    Kumar Garikapati Active Member

      We have a date format called Timestamp coming Via Azure Service bus and it is in this format /Date(1238626800000). Looking the best way to convert this into UTC.

        • 1. Re: Convert Timestamp to UTC
          Prakash Jain Guru

          Hi Kumar,

           

          Could you please elaborate on what would be your input and what do you expect?

           

           

          Thanks,

          Prakash Jain

          • 2. Re: Convert Timestamp to UTC
            Kumar Garikapati Active Member

            I am consuming AMQP Message using Application Integration and i am seeing the data like below..

             

               <headers>
               
            <name>JMSRedelivered</name>  
               
            <value>false</value>   </headers>
             
              
            <headers>
               
            <name>JMSTimestamp</name>  
               
            <value>1623254356515</value>   </headers>

             
              
            <headers>
               
            <name>JMSXDeliveryCount</name>  
               
            <value>1</value>   </headers>

             

            I need to convert the value under JMSTimestamp to UTC and incoming value data type is called timestamp.

            • 3. Re: Convert Timestamp to UTC
              Suvam Pani New Member

              Hi Kumar,

               

              Can you please confirm if the JMSTimestamp is Epoch time, i.e. difference between current time and 1970-01-01T00:00:00 in milliseconds?

               

              If so, you can use the following XQuery expression to convert into a readable dateTime format:

               

              let $epoch:= <JMSTimestamp data>

              return xs:dateTime("1970-01-01T00:00:00") + ($epoch * xs:dayTimeDuration('PT0.001S'))

               

              For example, the following expression returns 2021-06-09T15:59:16.515 :

               

              let $epoch:= 1623254356515

              return xs:dateTime("1970-01-01T00:00:00") + ($epoch * xs:dayTimeDuration('PT0.001S'))

               

              If the timestamp is already in UTC, then this expression can be used directly. Alternatively, the difference for different time zones can be added/subtracted as such:

               

              let $epoch:= <JMSTimestamp data>

              return xs:dateTime("1970-01-01T00:00:00") + ($epoch * xs:dayTimeDuration('PT0.001S')) + xs:dayTimeDuration('-PT4H') 

               

              Above duration is for EST (GMT -4).

               

              The epoch time can be directly converted into another timezone by using an expression as such:

               

              $epoch_UTC := $epoch + ($time_diff_in_hours*3600000)

               

              3600000 is the number of milliseconds in an hour.

               

              Please check if this helps.

               

              Thanks,

              Suvam