Use textscan to read dates with time zone

I have a text file containing dates of the format:
2016-01-03T16:00:10.000000000-06
The trailing -06 represents a time zone offset from GMT. The offset will take values other than -06. I don't need the offset and would like it to be ignored.
If all offset values were -06, I can read the dates in textscan using the format: {yyyy-MM-dd''T''HH:mm:ss.S''-06''}D However, this value will not always be -06.
Any advice on how to specify a date format that will ignore this trailing number? Note that I do not want to read the date in as a string. Appreciate any help you can offer.

 Réponse acceptée

Peter Perkins
Peter Perkins le 21 Sep 2017
I think you want the x format token .
>> datetime('2016-01-03T16:00:10.000000000-06','Format','yyyy-MM-dd''T''HH:mm:ss.SSSSSSSSSx','TimeZone','UTC+6')
ans =
datetime
2016-01-04T04:00:10.000000000+06
Notice that you MUST specify a single time zone for the result. datetime arrays have one time zone. So while you can read from dates in different zones, the result is automatically translated into the one you specify.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by