print a date and time in command window MATLAB I use matlab R2015a, when I run my script I want print the date and the time of exection 

I tried this code 

Dtimes=datetime('now','TimeZone','local','Format','d-MMM-y HH:mm:ss Z');
% the first test
disp(' Date and time is ' Dtimes ); % But not work
% second test
disp(sprintf('date and time is %s  ',Dtimes)) %also not work


But with this command is worked :

disp(sprintf('date and time is %s  ',datestr(now)));


What is the problem?
Based on Mathworks' documentation here, datetime returns an array, not a string. Therefore, you cannot use disp to display a string Date and time is together with that returned array.

Your second method is also not working because again Dtimes is an array and you cannot use %s to print it.

Your last method is working because datestr returns a string see documentation.

Please let me know if this explanation is not clear/enough.