Read in timestamps from weird time format

13 views (last 30 days)
Heidi Hirsh
Heidi Hirsh on 18 Feb 2019
Edited: Stephen on 19 Feb 2019
Hello! I am trying to read in data collected in CA. The timestamps are UTC times recorded as a string that includes characters I do not need. Can you help me figure out how to read in a column of timestamps that look likes this (see below). I want to end up with mtimes or even just separate the timestamps parts so that I can use datenum myself to reconnect the parts. Thank you! This is a column in a csv file if that makes a difference.
  1 Comment
Stephen on 19 Feb 2019
That is not a "weird time format" at all, they appear to be quite normal ISO 8601 timestamps:
ISO 8601 date formats are preferred for any situtuation where it is required to write dates that will be universally understood (e.g. data collection, filenames, data exchange, internet protocols, documentation, published articles, etc). Their ability to be sorted into chronological order with a basic character-sort makes them much more convenient to work with than any other date formats.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 18 Feb 2019
If the data is stored in a cell array of character vectors, S, then
datetime(S, 'InputFormat', 'uuuu-MM-dd''T''hh:mm:ss''Z''', 'TimeZone', 'UTC')
Walter Roberson
Walter Roberson on 19 Feb 2019
I had accidentally used hh where I should have used HH. With datetime(), hh is for 12 hour times, and HH is needed for 24 hour times.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!