How to assign UTC time?

41 views (last 30 days)
Marcel Geers
Marcel Geers on 16 Mar 2017
Edited: Marcel Geers on 17 Mar 2017
I have a timetable with data that has UTC +1 as timebase. Matlab provides the function timezones, which nicely shows the region, UTC offset and DST (daylight saving time) options. The data set does not have DST. I noticed that there is a region called "etc.", which doesn't include DST. For example, etc/GMT+1. To my surprise, the UTC offset is -1 and not +1 as I'd expect for, well, GMT +1. Why is it defined in the opposite way? When I look up GMT+1 and UTC+1, they should be the same, shouldn't they? So basically I have two questions: 1 Why does the timezone etc/GMT+1 have a negative UTC offset in Matlab? 2 What is the correct way to assign UTC+1 as timezone to a dataset in a timetable? Is this via etc/GMT-1?

Accepted Answer

Peter Perkins
Peter Perkins on 16 Mar 2017
It's a clash of conventions. Isn't it always? Some conventions define east as positive, some as negative. For the timezones function, "the list includes the offset from UTC (in hours, where east is positive)", so to get your timestamp, you take a UTC timestamp and add your offset (see my earlier comment). For reasons I've forgotten, the IANA time zone database uses the convention that west is positive: "In the "Etc" area, zones west of GMT have a positive sign and those east have a negative sign in their name (e.g "Etc/GMT-14" is 14 hours ahead/east of GMT.)"
And elsewhere on that page: "Sign is intentionally inverted." It's confusing. If it helps, you can do either of these as described in the datetime doc):
>> d.TimeZone = '+01:00'
d =
datetime
16-Mar-2017 23:06:01
>> d.TimeZone
ans =
'+01:00'
>> d.TimeZone = 'UTC+1'
d =
datetime
16-Mar-2017 23:06:01
Using a non-DST time zone is a bit unusual, and in some situations will garner you a warning that more or less says, "that time zone doesn't use DST, do you really want that?" I think that by, "The data set does not have DST", you mean that your timestamps are recorded in the local time 1 hour east (if I was a betting man) of UTC without DST adjustments, so I think yes, you really do want that.
  1 Comment
Marcel Geers
Marcel Geers on 17 Mar 2017
Edited: Marcel Geers on 17 Mar 2017
Peter, thank you for your answer and explanation. Indeed, I have different datasets, some have times referenced in UT(C), another in UTC+1 (and also a DST conversion, but that would overwrite one hour per year). I didn't know you could actually set the timezone to 'UTC' or 'UTC+x'. When retrieving the timezones with the function "timezones", I'd expect to get all the zones Matlab understands, yet it doesn't display 'UTC'. I did find the bit in the documentation about '+01:00'. I find it odd though that these different timezone conventions (east/west sign) are mixed within Matlab without explanation in the documentation.
edit: The 2016b documentation seems to also include the UTC zone description which I clearly overlooked, due to my focus on the timezones function.

Sign in to comment.

More Answers (1)

Jan
Jan on 16 Mar 2017
For the first part: Obviously "UTC offset" is the number, which must be added to the times to get the UTC time.
  2 Comments
Marcel Geers
Marcel Geers on 16 Mar 2017
Using that logic, selecting the time zone 'Europe/Amsterdam', which has an offset of +1, would require adding +1 to the time to get to UTC, which is wrong. It has an offset of +1 and I'd need to take the offset off Amsterdam time to get to the UTC time, which is one hour earlier (during winter) compared to Amsterdam.
Peter Perkins
Peter Perkins on 16 Mar 2017
timezones reports that Europe/Amsterdam has an offset of +1. So if you take a UTC timestamp, and add an hour to it, you'll get Amsterdam time. Or equivalently, If you take a UTC timestamp and convert it to Amsterdam time, it looks like you added an hour:
>> d = datetime('now','TimeZone','UTC')
d =
datetime
16-Mar-2017 22:06:01
>> d.TimeZone = 'Europe/Amsterdam'
d =
datetime
16-Mar-2017 23:06:01

Sign in to comment.

Categories

Find more on Dates and Time in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!