www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/DateAndTimeFromStringsWithLiteralCharactersExample.m

    %% Date and Time from Text with Literal Characters 
% Convert dates in ISO 8601 format to datetime values.
%%
% Create a cell array of character vectors containing dates in ISO 8601 format. In
% this format, the letter T is used as a delimiter that separates a date
% and a time. Each character vector includes a time zone offset. The letter Z indicates 
% no offset from UTC.
DateStrings = {'2014-05-26T13:30-05:00';'2014-08-26T13:30-04:00';'2014-09-26T13:30Z'} 
%%
% Convert the character vectors to datetime values. When specifying the input format, enclose
% the letter T in single quotes to indicate that it is a literal character.
% Specify the time zone of the output datetime array using the |TimeZone|
% name-value pair argument.
% 
t = datetime(DateStrings,'InputFormat','uuuu-MM-dd''T''HH:mmXXX','TimeZone','UTC')
%%
% The datetime values in |t| display in the default format.