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.

 채택된 답변

Peter Perkins
Peter Perkins 2017년 9월 21일

1 개 추천

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.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

질문:

2017년 9월 15일

답변:

2017년 9월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by