datenum - Parse ISO 8601 timestamp without applying UTC offset
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm using MATLAB R2014b-win64
When I call datenum with an ISO 8601 datenum, I get:
>> result = datenum('2015-05-01T00:00:01Z','yyyy-mm-ddTHH:MM:SSZ')
result =
736084.666678241
But this is not correct--MATLAB assumed I wanted the time changed from UTC to my local time zone:
>> datestr(result)
ans =
30-Apr-2015 16:00:01
If I leave off the 'Z' from the formatIn field, I get the right datenum:
>> result = datenum('2015-05-01T00:00:01Z','yyyy-mm-ddTHH:MM:SS')
result =
736085.000011574
>> datestr(result)
ans =
01-May-2015 00:00:01
I don't see anything about this in the documentation. Am I missing something?
Perhaps this is a bug?
1 comentario
per isakson
el 17 de Jun. de 2015
Editada: per isakson
el 18 de Jun. de 2015
Neither "UTC" nor "Z" is described on the page datenum, Convert date and time to serial date number - as far as I can see. If so, we may not make any assumptions on the behavior.
Respuestas (1)
Peter Perkins
el 18 de Jun. de 2015
Randall, this is indeed a bug, albeit for inputs that were never documented to work. Prior to R2013b, this generated an error. Although 'yyyymmddTHHMMSS' is a format documented to work in datenum/datevec/datestr, you've added a Z at the end, intended as "literal". That's the problem.
Two suggestions:
1) You're using R2014b. Consider using datetime instead of datenum:
>> datetime('2015-05-01T00:00:01Z','Format','yyyy-MM-dd''T''HH:mm:ss''Z''')
ans =
2015-05-01T00:00:01Z
Notice how I've "escaped" the two literals in the format. If you want to use time zones, datetime supports those, while datenum does not.
>> datetime('2015-05-01T00:00:01Z','TimeZone','local','Format','yyyy-MM-dd''T''HH:mm:ssz')
ans =
2015-04-30T20:00:01EDT
>> datetime('2015-05-01T00:00:01Z','TimeZone','UTC','Format','yyyy-MM-dd''T''HH:mm:ssXXX')
ans =
2015-05-01T00:00:01Z
2) Use strrep to strip the Z off your strings, and leave it out of the format.
Hope this helps.
Ver también
Categorías
Más información sobre Time Series Objects 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!