%% Convert 12-Hour Time String to 24-Hour Equivalent
% Convert the 12-hour time 05:32 p.m. to its 24-hour equivalent.

datestr('05:32 PM','HH:MM')

%
% Convert the 24-hour time 05:32 to its 12-hour equivalent.

datestr('05:32','HH:MM PM')

% The use of AM or PM in the formatOut output text does not influence which characters actually become part of the text; they only determine whether or not to include the characters. MATLAB® selects AM or PM based on the time entered.
% Copyright 2012 The MathWorks, Inc.