How do I convert timestamp to utc?

I have a date in this format: "YYYY-MM-DD HH:MM:SS+HHMM" how can I convert it to UTC?

write $zdth("2018-02-01 00:00:00+0600",3,5)
write $zdt("64680,0",3,5)

As you see, timezone is lost. Docs for $zdth in timeopt (5) state: Specify time in the form "hh:mm:ss+/-hh:mm" (24-hour clock). The time is specified as local time. The following optional suffix may be supplied, but is ignored: a plus (+) or minus (–) suffix followed by the offset of local time from Coordinated Universal Time (UTC)

  • 0
  • 0
  • 73
  • 0
  • 2


If you massage the timestamp format a bit so it is ISO8601/XSD compatible, you can use the XSDToLogical method of %TimeStamp to do the conversion for you:

DEV>Set ts = "2018-02-01 00:00:00+0600"
DEV>Set ts = $Translate(ts, " ", "T")
DEV>Set ts = $Extract(ts, 1, *-2)_":"_$Extract(ts, *-1, *)
DEV>Write ts
DEV>Write ##class(%TimeStamp).XSDToLogical(ts)
2018-01-31 18:00:00

If you are running Ensemble or HealthShare you may have a look at Ens.Util.Time or Ens.DataType.UTC. They provide an API to work with different time formats and also theire conversions. In Ens.DataType.UTC there is a method timeLocaltoUTC pass in you value and you don´t have to worry about.