MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Set Date and Time Display Format


In this section...
“Formats for Individual Date and Duration Arrays” on page 7-12
“datetime Display Format” on page 7-12
“duration Display Format” on page 7-13
“calendarDuration Display Format” on page 7-14
“Default datetime Format” on page 7-15

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.

7 Dates and Time

Free download pdf