3

I am trying to understanding the date reading of ISO 8601 format and cant find a good doc to read.

If I am getting time in my code like this "2018-08-18T00:00:00+1000", is this local time or UTC time? and when I convert it using Convert.ToDateTime("2018-08-18T00:00:00+1000"), I get the following date time {8/17/2018 7:00:00 AM}. I am not sure if that is UTC datetime or local?

What is the math behind "2018-08-18T00:00:00+1000" getting converted to {8/17/2018 7:00:00 AM}, I cant get my head around this.

Sarah
  • 1,199
  • 2
  • 21
  • 42
  • +1000 at the end means UTC + 10 hours and 0 minutes. You should check out what [wikipedia](https://en.m.wikipedia.org/wiki/ISO_8601) writes about ISO 8601. Regarding the conversion I don’t know, is it c# perhaps? I am sure such question has already been answered many times. – Joakim Danielson Aug 18 '18 at 07:40
  • Thanks Joakim, I put this question after reading wiki's page, it wasn't much helpful. As I did understand that UTC +10 hours but does that mean that date is local time or UTC? Also, yes that is c# code, +10 specially doesn't make sense when the code runs it puts the hours behind several hours... see from 8/18/2018 to 8/17/2018 7 am, clearly not +10 difference.. – Sarah Aug 19 '18 at 07:15
  • 1
    `+1000` means it's in the time zone UTC + 10 hours and if you are not in that time zone you will get a different time value when converting it and using local time. This is a tricky area and it is so easy to get it wrong, depending on what you want to do with the date it might be easiest to convert it to UTC first and then to your local time zone. Anyway, you should tag this question with `c#` if you want more help with the actual conversion. – Joakim Danielson Aug 19 '18 at 07:50

2 Answers2

1

You are asking for the math behind 2018-08-18T00:00:00+1000 being shown as 8/17/2018 7:00:00 AM.

First of all 8/17/2018 7:00:00 AM is just another format to display the date and time. Converted to an ISO 8601 string it would look like this: 2018-08-17T07:00:00.

+1000 at the end of the 2018-08-18T00:00:00+1000 representation is a timezone offset. You could read that string as August 18, 2018 in UTC plus ten hours. So it would be the same as 2018-08-18T10:00:00Z.

So we have a UTC date of August 18, 2018 10 AM, which is shown as a locale date of August 17, 2018 7 AM. That would mean that you are in a timezone which is 27 hours behind UTC.

A timezone behing more than 12 hours before (or 14 after) UTC does not exist (as far as I'm aware of). Therefore I assume that you have a typo in your example. Another reason could be a totally broken date parser.

But I still hope you got the math behind the conversion.

jelhan
  • 6,149
  • 1
  • 19
  • 35
  • Thanks much Jelhan for your help on this. Yes I understand that and thats exactly why I am confused how can it go back 27 hours back??? There is no timezone like that and still the code keeps returning me that. The only reason I can think of is that, internally its doing some math which is just not making sense. Is it possible that its taking 8/18/18 as local day and then doing some conversion. But thats exactly what c# code is returning and I cant get my head around it. – Sarah Sep 28 '18 at 16:56
0

Here is how I infer it

  • 2018-08-18T00:00:00+1000 //user's local time is 18Aug 00:00, 10 hours ahead UTC
  • 2018-08-17T14:00:00Z // same moment of time in UTC
  • 8/17/2018 7:00:00 AM // same moment of time in your local(server) time zone, 7 hours behind UTC

Now it is up to your code if you wanna use the +10 offset of the user or not.

See this for another example Do these date strings represent the same moment of time?

Tiju John
  • 933
  • 11
  • 28