MathWorks Machine Translation
The automated translation of this page is provided by a general purpose third party translator tool.
MathWorks does not warrant, and disclaims all liability for, the accuracy, suitability, or fitness for purpose of the translation.
Assign date and time components and specify datetime display format
The Format property controls the
display of datetime values. The other properties
control the values of components such as years and months in the datetime array.
Use dot notation to refer to a particular array and property:
t = datetime(2014,07,01,06,0,0); t.Format = 'MMMM d, y';
Format — Display format'default' | 'defaultdate' | character vectorDisplay format, specified as a character vector of the letters A-Z and a-z,
that correspond to the Unicode® Locale Data Markup Language (LDML)
standard for dates.
Example: 'eeee, MMMM d, yyyy HH:mm:ss' displays
a date and time such as Saturday, April
5, 2014 21:41:06.
The following tables show the letters you can use to construct
the value for Format. You can include nonletter
characters such as a hyphen, space, colon, or any non-ASCII characters
to separate the fields. To include the letters A-Z and a-z as
literal characters in the format, enclose them with single quotes.
Example: 'uuuu-MM-dd''T''HH:mm:ss' displays
a date and time, such as 2014-04-05T09:41:06.
The examples display the formatted output for the date, Saturday, April 5, 2014 at 9:41:06.12345 PM, in New York City.
Use these identifiers to specify the display formats of date and time fields.
| Letter Identifier | Description | Display |
|---|---|---|
G | Era | CE |
y | Year, with no leading zeros. See the Note that follows this table. | 2014 |
yy | Year, using last two digits. See the Note that follows this table. | 14 |
yyy, yyyy ... | Year, using at least the number of digits specified by the
number of instances of 'y' | For the year 2014, 'yyy' displays 2014,
while 'yyyyy' displays 02014. |
u, uu, ... | ISO year. A single number designating the year. An ISO year value assigns positive values to CE years and negative values to BCE years, with 1 BCE being year 0. | 2014 |
Q | Quarter, using one digit | 2 |
QQ | Quarter, using two digits | 02 |
QQQ | Quarter, abbreviated | Q2 |
QQQQ | Quarter, full name | 2nd quarter |
M | Month, numerical using one or two digits | 4 |
MM | Month, numerical using two digits | 04 |
MMM | Month, abbreviated name | Apr |
MMMM | Month, full name | April |
MMMMM | Month, capitalized first letter | A |
W | Week of the month | 1 |
d | Day of the month, using one or two digits | 5 |
dd | Day of the month using two digits | 05 |
D | Day of the year, using one, two or three digits | 95 |
DD | Day of the year using two digits | 95 |
DDD | Day of the year using three digits | 095 |
e | Day of the week, numerical using one or two digits. | 7, where Sunday is the first day of the
week. |
ee | Day of the week, numerical using two digits | 07 |
eee | Day, abbreviated name | Sat |
eeee | Day, full name | Saturday |
eeeee | Day, capitalized first letter | S |
a | Day period (AM or PM) | PM |
h | Hour, 12-hour clock notation using one or two digits | 9 |
hh | Hour, 12-hour clock notation using two digits | 09 |
H | Hour, 24-hour clock notation using one or two digits | 21 |
HH | Hour, 24-hour clock notation using two digits | 21 |
m | Minute, using one or two digits | 41 |
mm | Minute, using two digits | 41 |
s | Second, using one or two digits | 6 |
ss | Second, using two digits | 06 |
S, SS, ..., SSSSSSSSS | Fractional second, using the number of digits specified by
the number of instances of 'S' (up to 9 digits). | 'SSS' truncates 6.12345 seconds to 123. |
Note:
If you read a two-digit year number and specify the format as Use one or more Datetime values later than 144683 years CE or before 140743
BCE display only the year numbers, regardless of the specified |
Use these identifiers to specify the display format of the time zone offset. A time zone offset is the amount of time that a specific datetime is offset from UTC. This is different from a time zone, which comprises rules that determine the offsets that are used at specific times of the year. Include a time zone offset identifier in the display format for a datetime array when you want to ensure that the time components are displayed unambiguously.
| Letter Identifier | Description | Display |
|---|---|---|
z | Abbreviated name of the time zone offset. If this value is
not available, then the time zone offset uses the short UTC format,
such as UTC-4. | EDT |
Z | ISO 8601 basic format with hours, minutes, and optional seconds fields. | -0400 |
ZZZZ | Long UTC format. | UTC-04:00 |
ZZZZZ | ISO 8601 extended format with hours, minutes, and optional seconds fields. A time offset of zero is displayed as the ISO 8601 UTC indicator "Z". | -04:00 |
x or X | ISO 8601 basic format with hours field and optional minutes
field. If you specify X, a time offset of zero
is displayed as the ISO 8601 UTC indicator "Z". | -04 |
xx or XX | ISO 8601 basic format with hours and minutes fields. If you
specify XX, a time offset of zero is displayed
as the ISO 8601 UTC indicator "Z". | -0400 |
xxx or XXX | ISO 8601 extended format with hours and minutes fields. If
you specify XXX, a time offset of zero is displayed
as the ISO 8601 UTC indicator "Z". | -04:00 |
xxxx or XXXX | ISO 8601 basic format with hours, minutes, and optional seconds
fields. If you specify XXXX, a time offset of zero
is displayed as the ISO 8601 UTC indicator "Z". | -0400 |
xxxxx or XXXXX | ISO 8601 extended format with hours, minutes, and optional
seconds fields. If you specify XXXXX, a time offset
of zero is displayed as the ISO 8601 UTC indicator "Z". | -04:00 |
TimeZone — Time zone'' (default) | character vectorTime zone, specified as one of the following character vectors:
'', to create an "unzoned" datetime array
that does not belong to a specific time zone.
The name of a time zone region from the IANA Time
Zone Database, for example, 'America/Los_Angeles'.
The name of a time zone region accounts for the current and historical
rules for standard and daylight offsets from UTC that are observed
in a geographic region.
An ISO 8601 character vector of the form +HH:mm or -HH:mm,
for example, '+01:00', to specify a time zone that
is a fixed offset from UTC.
'UTC', to create a datetime array
in Universal Coordinated Time.
'UTCLeapSeconds', to create a datetime array
in Universal Coordinated Time that accounts for leap seconds.
'local', to create a datetime array
in the system time zone. When you query the TimeZone property,
the IANA value is returned.
This table lists some common names of time zone regions from the IANA Time Zone Database.
Value of TimeZone | UTC Offset | UTC DST Offset |
|---|---|---|
'Africa/Johannesburg' | +02:00 | +02:00 |
'America/Chicago' | −06:00 | −05:00 |
'America/Denver' | −07:00 | −06:00 |
'America/Los_Angeles' | −08:00 | −07:00 |
'America/New_York' | −05:00 | −04:00 |
'America/Sao_Paulo' | −03:00 | −02:00 |
'Asia/Hong_Kong' | +08:00 | +08:00 |
'Asia/Kolkata' | +05:30 | +05:30 |
'Asia/Tokyo' | +09:00 | +09:00 |
'Australia/Sydney' | +10:00 | +11:00 |
'Europe/London' | +00:00 | +01:00 |
'Europe/Zurich' | +01:00 | +02:00 |
You also can use the timezones function to
display a list of IANA time zone names that the datetime function
accepts.
Data Types: char
Year — Year numberYear number of each value in the datetime array,
specified as a scalar or a vector, matrix, or multidimensional array
the same size and shape as the datetime array.
Each year number is an integer value based on the ISO calendar. Years
in the current era are positive and years in the previous era are
zero or negative. For example, the year number of 1 BCE is 0.
If you set the Year property to a nonleap
year for a datetime value that occurs on a leap
day (February 29), then the Day and Month properties
change to March 1.
Month — Month numberMonth number of each value in the datetime array,
specified as a scalar or a vector, matrix, or multidimensional array
the same size and shape as the datetime array.
Each month number is an integer value from 1 to 12. If you set a value
outside that range, then the Year property adjusts
accordingly, and the Month property stays within
the range 1 to 12. For example, month 0 corresponds to month 12 of
the previous year. For historical dates, the month number is based
on the proleptic Gregorian calendar.
Day — Day-of-month numberDay-of-month number of each value in the datetime array,
specified as a scalar or a vector, matrix, or multidimensional array
the same size and shape as the datetime array.
Each day-of-month number is an integer value from 1 to 28, 29, 30,
or 31, depending on the month and year. If you set a value outside
that range, then the Month and Year properties
adjust accordingly, and the Day property stays
within the appropriate range. For example, day 0 corresponds to the
last day of the previous month. For historical dates, the day number
is based on the proleptic Gregorian calendar.
Hour — Hour numberHour number of each value in the datetime array,
specified as a scalar or a vector, matrix, or multidimensional array
the same size and shape as the datetime array.
Each hour number is an integer value from 0 to 23. If you set a value
outside that range, then the Day, Month,
and Year properties adjust accordingly, and the Hour property
stays within the appropriate range. For example, hour -1 corresponds
to hour 23 of the previous day.
The following apply to datetime arrays with a specific time zone that follows daylight saving time:
If you specify a value for the Hour property
that would create a nonexistent datetime in the hour gap when daylight
saving time begins, the value of the Hour property
adjusts to the next hour.
If you specify a value for the Hour property
that would create an ambiguous datetime in the hour overlap when daylight
saving time ends, then the datetime adjusts to the second of the two
times (in standard time) with that hour.
Minute — Minute numberMinute number of each value in the datetime array,
specified as a scalar or a vector, matrix, or multidimensional array
the same size and shape as the datetime array.
Each minute number is an integer value from 0 to 59. If you specify
a value outside that range, then the Hour, Day, Month,
and Year properties adjust accordingly, and the Minute property
stays within the appropriate range. For example, minute -1 corresponds
to minute 59 of the previous hour.
Second — SecondSecond of each value in the datetime array,
specified as a scalar or a vector, matrix, or multidimensional array
the same size and shape as the datetime array.
Each second value is a floating-point value ordinarily ranging from
0 to less than 60. If you set a value outside that range, then the Minute, Hour, Day, Month,
and Year properties adjust accordingly, and the Second
property stays within the appropriate range. For example, second -1
corresponds to second 59 of the previous minute.
A datetime array with a TimeZone value
of 'UTCLeapSeconds' has seconds ranging from 0
to less than 61. The values from 60 to 61 represent datetimes that
occur during a leap second.
SystemTimeZone — System time zone settingThis property is read only.
System time zone setting, specified as a character vector. This time zone setting is determined by the system on which MATLAB® is running.
Example: America/New_York
You can also select a location from the following list: