1
0
-1

Hi all,

is there a simple way to convert UTC format like, for example,  "2019-06-06T08:58:42.1878669Z" to a local time zone considering also daylight period ?


Many thanks

Luigi Giuliante


    CommentAdd your comment...

    4 answers

    1.  
      1
      0
      -1

      Not very refined, but it should work:


      variables
        string vNlsInternalTime
        string vUTCDateTime
        datetime vDateTime
      endvariables
      
      vNlsInternalTime = $nlsinternaltime
      $nlsinternaltime = "UTC"
      vUTCDateTime = "2019-06-06T08:58:42.1878669Z"
      ; replace all non numeric characters in the input string
      vUTCDateTime = $replace(vUTCDateTime, 1, "-", "", -1)
      vUTCDateTime = $replace(vUTCDateTime, 1, '&', "", -1)
      vUTCDateTime = $replace(vUTCDateTime, 1, ":", "", -1)
      vUTCDateTime = $replace(vUTCDateTime, 1, ".", "", -1)
      ; convert string to datetime
      vDateTime = $datim(vUTCDateTime[1:16])
      ; First value is the internal datetime value in UTC
      ; Second value (substituted string) is the local time
      putmess $concat(vDateTime, " - ", "%%vDateTime")
      $nlsinternaltime = vNlsInternalTime

      Result: 

      "2019060608584218 - 06-jun-19 10:58:42"

      I hope this helps.

      Kind regards,
      Daniel

        CommentAdd your comment...
      1.  
        1
        0
        -1

        It's a bit late (smile) but another option is to base the conversion on Uniface, which is able to understand xsd:datetime when handling XML.

        So, a temporary XML and XSD is made in order to perform the conversion.

        entry LP_CONVERT
            params
                string C_DATE : in
                datetime E_DATE : out
            endparams
                  
            variables
                string VXDATE
                struct VSDATE 
            endvariables
        	;write XML data
            VXDATE = $concat("<?xml version=%%"1.0%%" encoding=%%"UTF-8%%"?><d>", C_DATE, "</d>")
        	;prepare temporal xsd
            filedump/text $xsd, "schema.xsd"
        	;convert XML to Struct using schema
            xmltostruct/schema VSDATE, VXDATE, "schema.xsd"
            if ($status >= 0) E_DATE = VSDATE->d->$scalar
            filedelete "schema.xsd"
             
             
        xsd:blockdata #<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
          <xs:element name="d" type="xs:dateTime"/>
        </xs:schema>#
        end

        So, you can use it with any xsd:datetime valid format.

        variables
        	string vString
        	datetime vTimestamp
        	string vNlsInternalTime
        endvariables
        vNlsInternalTime = $nlsinternaltime
        $nlsinternaltime = "UTC"
        
        vString = "2019-06-06T08:58:42.1878669Z" ;Zulu
        call LP_CONVERT(vString, vTimestamp)
        
        vString = "2019-06-06T08:58:42.1878669+09:00" ;at Tokio
        call LP_CONVERT(vString, vTimestamp)
        
        $nlsinternaltime = vNlsInternalTime



        Regards


        Luis

          CommentAdd your comment...
        1.  
          1
          0
          -1

          Very perfect.


          Many thanks

          Luigi

          1. Daniel Iseli

            You are welcome.

            Kind regards,
            Daniel

          CommentAdd your comment...
        2.  
          1
          0
          -1

          Hi Daniel,

          I'll try it right away and thank you for your quick reply.


          My best regards

          Luigi Giuliante


            CommentAdd your comment...