Set Date and Time Display Format
In this section...
“Formats for Individual Date and Duration Arrays” on page 7-10
“datetime Display Format” on page 7-10
“duration Display Format” on page 7-11
“calendarDuration Display Format” on page 7-11
“Default datetime Format” on page 7-12
Formats for Individual Date and Duration Arrays
datetime, duration, and calendarDuration arrays have a Format property that controls the
display of values in each array. When you create a datetime array, it uses the MATLAB global default
datetime display format unless you explicitly provide a format. Use dot notation to access the Format
property to view or change its value. For example, to set the display format for the datetime array,
t, to the default format, type:
t.Format = 'default'
Changing the Format property does not change the values in the array, only their display. For
example, the following can be representations of the same datetime value (the latter two do not
display any time components):
Thursday, August 23, 2012 12:35:00
August 23, 2012
23-Aug-2012
The Format property of the datetime, duration, and calendarDuration data types accepts
different formats as inputs.
datetime Display Format
You can set the Format property to one of these character vectors.
Value of Format
Description
'default'
Use the default display format.
'defaultdate'
Use the default date display format that does not
show time components.
To change the default formats, see “Default datetime Format” on page 7-12.
Alternatively, you can use the letters A-Z and a-z to specify a custom date format. You can include
nonletter characters such as a hyphen, space, or colon to separate the fields. This table shows several
common display formats and examples of the formatted output for the date, Saturday, April 19, 2014
at 9:41:06 PM in New York City.
Value of Format
Example
'yyyy-MM-dd'
2014-04-19
7 Dates and Time
7-10
Précédent

- 264/1450

Suivant