32
Views
5
Comments
Solved
TextToDateTime() and JSON Deserializer with time zone offsets. 
Question

I am trying to convert a timestamp value with a time zone offset from ISO8601 format into a DateTime format.

I am using the TextToDateTime() function.

An example would be:

TextToDateTime("2020-06-26T10:30:00+02:00")

Which returns a value of 2020-06-26 08:30
The expected result is: 2020-06-26 12:30


I would just like to understand if this is the result of some time zone conversion that I am not quite grasping, or could it be a bug?

I am using a Traditional Web App.
Both my server and the device time zones are set to UTC+0.

mvp_badge
MVP
Rank: #2
Solution

Hi Larissa,

Daryna is right. The first part of "2020-06-26T10:30:00+02:00" means that it's 10:30:00 on 26 June 2020 local time, the last part means that local time is two hours ahead ("+02:00") of UTC.

Since Traditional Web Apps are always assuming local time, and your local time is actually UTC, TextToDateTime() converts "2020-06-26T10:30:00+02:00" to 26 June 2020, 8:30:00. So there's no magic happening, it's a rather straightforward conversion of an ISO8601 date to local time (which happens to be UTC).

Rank: #552

Hi Larissa,

Why do you expect 2020-06-26 12:30? 

When the time is 10:30 in the UTC+2 time zone, it is 8:30 in the UTC time zone.

Rank: #5223

Larissa le Roux wrote:

I am trying to convert a timestamp value with a time zone offset from ISO8601 format into a DateTime format.

I am using the TextToDateTime() function.

An example would be:

TextToDateTime("2020-06-26T10:30:00+02:00")

Which returns a value of 2020-06-26 08:30
The expected result is: 2020-06-26 12:30


I would just like to understand if this is the result of some time zone conversion that I am not quite grasping, or could it be a bug?

I am using a Traditional Web App.
Both my server and the device time zones are set to UTC+0.

 

 Hi try to use this component try to use this component TimezoneReactiveUtils.

Best regards

mvp_badge
MVP
Rank: #2
Solution

Hi Larissa,

Daryna is right. The first part of "2020-06-26T10:30:00+02:00" means that it's 10:30:00 on 26 June 2020 local time, the last part means that local time is two hours ahead ("+02:00") of UTC.

Since Traditional Web Apps are always assuming local time, and your local time is actually UTC, TextToDateTime() converts "2020-06-26T10:30:00+02:00" to 26 June 2020, 8:30:00. So there's no magic happening, it's a rather straightforward conversion of an ISO8601 date to local time (which happens to be UTC).

Rank: #8009

Hi All, thanks for the replies, I indeed understood the conversion wrong, it is much clearer now - thanks for explaining. 


mvp_badge
MVP
Rank: #2

You're most welcome! Timezones are these pesky things that are difficult to grasp sometimes, I hope I increased your understanding a bit :).