MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Name Size Bytes Class Attributes


d 1x20 40 char
t 1x1 17 datetime


Convert a datetime array to a character vector using char or cellstr. For example,
convert the current date and time to a timestamp to append to a file name.


t = datetime('now','Format','yyyy-MM-dd''T''HHmmss')


t =


datetime


2017-01-03T151105


S = char(t);
filename = ['myTest_',S]


filename =


'myTest_2017-01-03T151105'


Convert Between Datetime and String Arrays


Starting in R2016b, you can use the string function to create a string array. If a string
array contains date strings, then you can convert the string array to a datetime array
with the datetime function. Similarly, you can convert a datetime array to a string
array with the string function.


Convert a string array. MATLAB displays strings in double quotes. For best performance,
specify the format of the input date strings as an input to datetime.


str = string({'24-Oct-2016 11:58:17';
'19-Nov-2016 09:36:29';
'12-Dec-2016 10:09:06'})


str =


3×1 string array


"24-Oct-2016 11:58:17"
"19-Nov-2016 09:36:29"
"12-Dec-2016 10:09:06"


Convert Between Datetime Arrays, Numbers, and Text
Free download pdf