How to assign UTC time?
31 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Marcel Geers
el 16 de Mzo. de 2017
Editada: Marcel Geers
el 17 de Mzo. de 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?
0 comentarios
Respuesta aceptada
Peter Perkins
el 16 de Mzo. de 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 comentario
Más respuestas (1)
Jan
el 16 de Mzo. de 2017
For the first part: Obviously "UTC offset" is the number, which must be added to the times to get the UTC time.
2 comentarios
Peter Perkins
el 16 de Mzo. de 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
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!