Skip to main content

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


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


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


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


Hi Daniel,

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


My best regards

Luigi Giuliante



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


Very perfect.


Many thanks

Luigi


Very perfect.


Many thanks

Luigi

You are welcome.

Kind regards,
Daniel


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


It's a bit late 🙂 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("", C_DATE, "")
	;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 #
  
#
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